palindrome numbers between 1 to 1000 using function int reverse(int n) which returns reverse of n
in java
Answers
Answer:
The program will prompt user to input the number and then it will reverse the same number using while loop.
import java.util.Scanner;
class ReverseNumberWhile
{
public static void main(String args[])
{
int num=0;
int reversenum =0;
System.out.println("Input your number and press enter: ");
//This statement will capture the user input
Scanner in = new Scanner(System.in);
//Captured input would be stored in number num
num = in.nextInt();
//While Loop: Logic to find out the reverse number
while( num != 0 )
{
reversenum = reversenum * 10;
reversenum = reversenum + num%10;
num = num/10;
}
System.out.println("Reverse of input number is: "+reversenum);
}
Output:
Input your number and press enter:
145689
Reverse of input number is: 986541