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 :: find shortest string in array java 
Java :: jackson ignore value if null 
Java :: abstract vs final 
Java :: how to make a char uppercase in java 
Java :: what is the difference between sc.nextLine() and sc.next() in java 
Java :: object to array java 
Java :: print line in jjava 
Java :: java get current date without time 
Java :: how to the text of an element in selenium java 
Java :: hibernate create query count return 
Java :: find if a number is in a 2d array java 
Java :: java set label color 
Java :: java array to list 
Java :: java number 
Java :: How to perform counting sort in Java? 
Java :: public static void main(string args) 
Java :: capitalize string java 
Java :: Read from text file android studio 
Java :: {} when initialising arraylist java 
Java :: how to create an array list of ints in java 
Java :: setbounds in java 
Java :: convert list of integer to array in java 
Java :: i have AdoptOpenJDK 8 but java --version gettinbg Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: spinner event in android 
Java :: java generate random id 
Java :: jframe visible 
Java :: RecyclerView: No layout manager attached; skipping layout 
Java :: java double format 
Java :: java variables in annotations 
Java :: java replace all not number 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =