Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java code to reverse an integer

public class ReverseNumberExample1   
{  
public static void main(String[] args)   
{  
int number = 987654, reverse = 0;  
while(number != 0)   
{  
int remainder = number % 10;  
reverse = reverse * 10 + remainder;  
number = number/10;  
}  
System.out.println("The reverse of the given number is: " + reverse);  
}  
}  
Comment

reverse a integer in java

while(num != 0) 
{
   int digit = num % 10;
   reversed = reversed * 10 + digit;
   num /= 10;
}
Comment

reverse number in java

import java.util.*;
class reverse
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter String: ");
        String str = sc.next();
        char d;
        String str2 = "";
        int l = str.length();
        for(int i = l-1; i >= 0; i--)
        {
            d = str.charAt(i);
            str2 = str2 + d;
        }
        System.out.println(str2);
        sc.close();
    }
}
Comment

how to reverse a number in java

int rev= 0;
while(num > 9)
{
  rev= rev*10 + num%10;
  num/= 10;
}
Comment

reverse number in java

class Main {
  public static void main(String[] args) {

    int num = 1234, reversed = 0;
    
    System.out.println("Original Number: " + num);

    // run loop until num becomes 0
    while(num != 0) {
    
      // get last digit from num
      int digit = num % 10;
      reversed = reversed * 10 + digit;

      // remove the last digit from num
      num /= 10;
    }

    System.out.println("Reversed Number: " + reversed);
  }
}
Comment

java number reverse

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();

        int rev = 0;

        while (num > 0) {
            rev = rev * 10 + num % 10;
            num /= 10;
        }
        System.out.println(rev);
    }
Comment

reverse number java

import java.util.Scanner;

public class App1 {
    public static void main(String[] args) {
        Scanner scannerNum = new Scanner((System.in));
        int number , sum = 0;
        number = scannerNum.nextInt();

       
        System.out.println("sum = " + sum);*/
        int result = 0 , digit;
        while(number != 0)
        {
            result *= 10;
            digit = number % 10;
            result += digit;
            number = number / 10;
        }
        System.out.println("result = " + result);


    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: android studio space 
Java :: java wrapper classes 
Java :: for each loop in java 
Java :: java load jar at runtime 
Java :: 2048 java code 
Java :: reverse a doubly linked list 
Java :: android studio check if email is valid java 
Java :: java assert 
Java :: java developer interview questions 
Java :: java jbutton get background color 
Java :: get distinct values from list of objects java 
Java :: java record 
Java :: find first and last position of element in sorted array 
Java :: java change hashmap value 
Java :: Java Remove HashMap Elements 
Java :: how to start array index from 1 in java 
Java :: java for loop syntax 
Java :: position of an element in infinite sorted array 
Java :: navigation bottom android 
Java :: GridLayout 
Java :: insert node at end of doubly linked list 
Java :: java long literal 
Java :: java map sorted by key 
Java :: java "-" 
Java :: convert python to java 
Java :: Method Overloading by changing the data type of parameters Java 
Java :: assign a random number in a set without replacement javva 
Java :: java method overloading 
Java :: Kadane Algorithm for maximum sub-array 
Java :: enable GPS inside of application 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =