Write the java program To Reverse Number
REVERSE
import java.io.*;
class reverse
{
public static void
main(String args[])throws IOException
{
BufferedReader in=new
BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number");
int num=Integer.parseInt(in.readLine());
int n=num;
int temp=0,rem=0,sum=0;
while(num>0)
{
temp=num%10;
rem=rem*10+temp;
num=num/10;
sum=sum+temp;
}
System.out.println(rem+" is a reverse of "+n);
System.out.println(sum+" is the sum of digit "+n);
}
}
OUTPUT
C:\Program Files\Java\jdk1.5.0\bin>java reverse
Enter a number
1234
4321 is a reverse of 1234
10 is the sum of digit 1234
No comments:
Write comments