About Me

header ads

Java Program For Reversing A Number As Input


Java Program For Reversing A Number As Input


import java.util.Scanner;

class ReverseNumber
{
   public static void main(String args[])
   {
      int n, reverse = 0;

      System.out.println("Enter the number to reverse");
      Scanner in = new Scanner(System.in);
      n = in.nextInt();

      while( n != 0 )
      {
          reverse = reverse * 10;
          reverse = reverse + n%10;
          n = n/10;
      }

      System.out.println("Reverse of entered number is "+reverse);
   }
}


Output:

Enter the number to reverse 
1234
Reverse of entered number is 4321


Back


Post a Comment

0 Comments