Write a program to print reverse of a number of the given number.
Input: 987654321
Output: 123456789
import java.io.*; import java.util.*; public class temp { public static void main(String[] args) { int no , rem ,rev = 0; Scanner scan = new Scanner(System.in); System.out.println("Enter a number: "); no = scan.nextInt(); while(no > 0){ rem = no % 10; rev = (rev*10) + rem; no = no / 10; } System.out.println("Reversed No: "+rev); } }
INPUT_1:
Enter a number:
1234
OUTPUT:
Reversed No: 4321
INPUT_2:
Enter a number:
7859
OUTPUT:
Reversed No: 9587
INPUT_3:
Enter a number:
6969
OUTPUT:
Reversed No: 9696
INPUT_4:
Enter a number:
69
OUTPUT:
Reversed No: 96
INPUT_5:
Enter a number:
2486
OUTPUT:
Reversed No: 6842
ILLUSTRATION