wap a program in Java to print the reverse of a number input by the user
Answers
Answered by
3
Answer:
WAP a program in Java to print the reverse of a number input by the user
Explanation:
public class FindReverseNumber {
public static void main(String[] args) {
//number defined
int n;
int reversedNumber = 0;
int temp = 0;
System.out.println("Enter an integer to reverse");
Scanner in = new Scanner(System.in);
n = in.nextInt();
while (number & gt; 0) {
//modulus operator used to strip off the last digit
temp = number % 10;
//create reversed number
reversedNumber = reversedNumber * 10 + temp;
number = number / 10;
}
//output
System.out.println("Reversed Number is: " + reversedNumber);
}
}
Output:-
Enter the number to reverse: 123
Reversed Number is: 321
Similar questions