how to print reverse of number in java
For Example number is 5786 Reverse is 6875
Firstly We Will Take a input from user using scanner class if you not know about what is the scanner class in java no problem you can checkout What Is Scanner Class In JAVA
Now We Will Write Our Program
import java.util.Scanner;
class ReverseofNuber {
public static void main(String[] args) {
int number, reverse = 0;
Scanner kb = new Scanner(System.in);
System.out.println("Enter you Number To Reverse :");
number = kb.nextInt();
while (number != 0) {
reverse = reverse * 10;
reverse = reverse + number % 10;
number = number / 10;
}
System.out.println("Reverse Of The number is " + reverse);
}
}
In starting i have imported Scanner class to take input from user after that i have created a class then a public void function then created a variable number to store a number and reverse to store reverse of the number then created a Scanner Object then Printed a message to tell the user for give input then stored user input in variable then used a loop which reverse the number and then printed the reverse of the number if you have any doubt in above program you can ask me in the comment section
Making money as a coder in 2025 is not much of a big or tough…
Lloyds Technology Centre, A tech and data company located in Hyderabad, India. They are part of…
How to Increase Height at Any Age Rise Above: How to Increase Height at Any…
In the fast-paced digital world, we often forget the timeless beauty that nature offers. Today,…
Top 10 Deadliest Kicks in Martial Arts: Master the Art of Knockouts Martial arts is…
How to Optimize Battery Life of Your Smartphone: Tips and Tricks for Prolonging Battery Health…