Java programming tutorials
Write your first Java class, practice control flow and collections, and use the library guides to work with text, files, dates, and exceptions.
Java core curriculum
Getting started
Decisions and loops
Functions and data
Files and projects
Reverse the digits of a number
class ReverseNumber {
public static void main(String[] args) {
int input = 123;
int temp, r, output = 0;
temp = input;
while (temp > 0) {
r = temp % 10;
temp = temp / 10;
output = output * 10 + r;
}
System.out.println("Original Number : " + input);
System.out.println("Reverse Number : " + output);
}
}
Original Number : 123 Reverse Number : 321