Reversing

Report a typo

Write a program that reads a three-digit integer number, calculates a new number by reversing its digits, and finally outputs the new number.

Hint

You can use the modulus operation to extract single digits from an integer. For example, 238 % 10 gives 8. Then you can divide by 10 like this 238 / 10 to get 23. You can use modulus again, for example 23 % 10, to extract 3. Repeat the steps again to get the final value 2. Remember to store each extracted value in a different variable. To reconstruct the reversed number, multiply by 10 and add the number in reverse order. For example, 8 * 10 = 80 then 80 + 3 = 83. Finally, 83 * 10 = 830 and 830 + 2 = 832.

Sample Input 1:

320

Sample Output 1:

23

Sample Input 2:

976

Sample Output 2:

679
Write a program in Java 17
import java.util.Scanner;

class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// put your code here
}
}

Create a free account to access the full topic