
Write a program that prompts the user to input an integer and the output the number with the digits reversed. For example if the input is 12345, the output should be 54321.

Hi Friend,
Try this:
import java.util.*;
public class ReverseNumber {
public static int reverse(int num){
int n = num;
int reversedNumber = 0;
for (int i = 0; i <= num; i++) {
int r = num % 10;
num = num / 10;
reversedNumber = reversedNumber * 10 + r;
i = 0;
}
return reversedNumber;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number: ");
int num = input.nextInt();
System.out.println("Reversed Number: "+reverse(num));
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.