Sample input and output:
Example 1:
Input: 25
Output: 52
Example 2:
Input: 123
Output: 321
Example 3:
Input: 3
Output: 3
import java.util.*;
public class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int num = 1234, reversed = 0;
System.out.print("Enter number: ");
num = keyboard.nextInt();
while(num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
System.out.println("Reversed Number: " + reversed);
keyboard.close();
}
}
Comments
Leave a comment