63. JAVA Program To find the Reverse of A Given Number
How does this program work?
- This program is used to find the Reverse of a given number using JAVA.
- The integer entered by the user is stored in variable n.
- Declare variable r to store reverse number and initialize it with 0.
- Multiply the reverse number by 10, add the remainder which comes after dividing the number by 10.
Here is the code
//Reverse Number.
import java.util.Scanner;public class Reverse
{
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter an integer:" );
Scanner obj = new Scanner(System.in );;
n = obj.nextInt();
while(n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
System.out.println("Reverse of the number is" + reverse);
}
}