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

how to reverse numbers in java

    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 :: initialize empty dictionary java 
Java :: fix nullpointerexception 
Java :: arrays methods in java 
Java :: How do I make my Android app scrollable? 
Java :: stringbuilder with delimiter java 
Java :: java continue statement 
Java :: greatest of three in java 
Java :: determine if a number is factorial in Java 
Java :: java interview questions 
Java :: linear serach in java 
Java :: garbage collection in java 
Java :: java arraylist initialize with 0 
Java :: set web image to imageview android java 
Java :: java 14 switch 
Java :: java array slicing 
Java :: java final modifier on method 
Java :: how to close scanner in java 
Java :: unresolved reference activity_main 
Java :: java return pair 
Java :: array to array list java 
Java :: how to remove leading space in java 
Java :: runtime exception in java 
Java :: java hashmap replace 
Java :: java convert int to string 
Java :: how to et curent directory in java 
Java :: BufferedReader x = new BufferedReader(new InputStreamReader(System.in)); 
Java :: Algorithms - sum 
Java :: intergers are appearing as string in Json 
Java :: REGEX ___ get length of array in java 
Java :: split by asterisk java 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =