Reverse of a Number
Reverse of a Number
Program to display reverse of a number
Example : Original Number : 423
Reverse Number : 234
Program below :-
import java.io.*;
import java.util.*;
class Reverse
{
public static void main(String args[])
{
Scanner in= new Scanner(System.in);
int n,p,rev,s=0;
System.out.println("Enter No.");
n= in.nextInt(); // Input number from user
p=n; // store the entered number in "p" variable
while(n>0)
{
rev=n%10; // extract last digit of the number
s=s*10+rev; // store the digit last digit
n=n/10; // extract all digit except the last
}
System.out.println("Original Number : "+p);
System.out.println("Reverse Number : "+s);
} // end of main method
} // end of class
Comments
Post a Comment