Sunday 18 September 2016

CODE to reverse a number in JAVA

import java.util.Scanner;   // Scanner class is impoerted to perform input functions
class Rev
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);   // Creating Object of Scanner Class
int s=0,n,r;            
n=in.nextInt();    // Taking input form user and storing in 'n' variable.
while(n!=0)
{
r=n%10;             // remainder is determined(if n is 998 then r will be 8)
s=s*10+r;          
n=n/10;
}
System.out.println("Revers is "+s);
}
}




No comments:

Post a Comment