Sunday, August 12, 2012

Java program to find reverse of a number


import java.io.*;
class reversenum
{
int num,dup,rev,rem;
reversenum()
{
rev=rem=0;
}
void get()throws IOException
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number : ");
num=Integer.parseInt(br.readLine());
dup=num;
while(dup>0)
{
rem=dup%10;
rev=rev*10+rem;
dup=dup/10;
}
}
void disp()
{
System.out.println("\nThe reverse of " +num+" is "+rev);
}
public static void main(String[] args)throws IOException
{
reversenum r=new reversenum();
r.get();
r.disp();
}
}

No comments:

Post a Comment