Program that reads a integer number and printthe reverse of it using function.

import java.io.*;
class reverse
{ private int a,b,c,d;
int reversedigit(int x)
{
a=x%10;
x=x/10;
b=x%10;
x=x/10;
c=x%10;
x=x/10;
d=x%10;

return(a*1000+b*100+c*10+d);
}

}
class main
{ public static void main(String[] asd)throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
int n;
String num;
reverse d=new reverse();
System.out.println("Enter a four digit number::");
num=obj.readLine();
n=Integer.parseInt(num);
System.out.println("Reverse number= "+d.reversedigit(n)+".");
}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s