Find out Reverse Number of a given Number.
import java.io.*;
class ReverseOfNum
{
public static void main(String args[]) throws IOException
{
int num, temp,reverse=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Number You Want to Reverse : ");
num=Integer.parseInt(br.readLine());
while(num>0)
{
temp=num%10;
reverse=reverse*10+temp;
num=num/10;
}
System.out.println("Result is : " + reverse);
}
}
{
public static void main(String args[]) throws IOException
{
int num, temp,reverse=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Number You Want to Reverse : ");
num=Integer.parseInt(br.readLine());
while(num>0)
{
temp=num%10;
reverse=reverse*10+temp;
num=num/10;
}
System.out.println("Result is : " + reverse);
}
}
- Save the file with name ReverseOfNum .java
- Complie with: javac ReverseOfNum .java
- Run with: java ReverseOfNum