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
Prem Tiwari is the founder of FreeWebMentor.com and also a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies. View all posts by Prem Tiwari
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