Java Program

Object:-Write a Program in java to find out the reverse of the number.

import java.util.Scanner; 
class Reverse
{
 public static void main(String...s)
 {
  int n,rev=0,i;
  Scanner sc = new Scanner(System.in); 
  System.out.println("Enter any number: ");
  n = sc.nextInt();        
  while(n!=0)
  {
   i=n%10;
   rev=(rev*10)+i;
   n/=10;
  }        
  System.out.println("Reverse = "+rev);
  sc.close();
  }
}

Output

Enter any number: 1234

Reverse = 4321
 

Explanation

For example if given number is 1234 then its reverse will be 4321.








You may also like: