This is the java program to find the reverse of a number. It can be done by using mod operator ,it returns the remainder. if we use that mode with 10 , then it returns last digit of a number. So we will extract all digits in a number and multiply with 10. Consider the following program to find reverse of number in java.
/* java program to find reverse of number */
import java.io.*;
class reverse
{
public static void main(String args[]) throws Exception
{
int sum, i,a,d;
System.out.println("Enter A Number ");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
a = Integer.parseInt(k.readLine());
sum = 0;
while(a!=0)
{
d = a%10;
sum=sum*10+d;
a = a/10;
}
System.out.println("Reverse Of a number :"+sum);
}
}
Output:
/* java program to find reverse of number */
import java.io.*;
class reverse
{
public static void main(String args[]) throws Exception
{
int sum, i,a,d;
System.out.println("Enter A Number ");
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
a = Integer.parseInt(k.readLine());
sum = 0;
while(a!=0)
{
d = a%10;
sum=sum*10+d;
a = a/10;
}
System.out.println("Reverse Of a number :"+sum);
}
}
Output: