In this program, I will share to how to write a Java program to reverse any given number. When you execute this program, it asks you to enter any number and then it will reverse that number and print as output.
Copy the below program and execute it to any number with the help of Java programming language.
public static void main(String args)
int n, reverse = 0;
System.out.println("Please enter any number to reverse:");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while( n != 0 )
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
System.out.println("The reversed number is: "+reverse);
Please enter any number to reverse:
The reversed number is:54
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Java program, java program to reverse any number, Java programming, Java programs with examples, Java programs with output, java tutorial, Java tutorials, reserve of a number in java, reverse integer in java, reverse the number, sample program reserve number