What is a palindrome number?
A number is said to be a Palindrome number if it remains the same when its digits are reversed or are the same as forward. It is also applied to the word, phrase, or other sequences of symbols.
For example: 14141, 777, 272 are palindrome numbers as they remain the same even if reversed. If we take the example of ‘mam’ or ‘madam’, these are also palindrome words.
Java Program to Check whether the Number is Palindrome or not using While loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | //check the number for Palindrome using while loop(user inputs) in java import java.util.Scanner; public class PalindromeCheck { public static void main(String[] args) { int n, rev = 0, remainder, originalNumber; Scanner sc = new Scanner(System.in); System.out.print("Enter an integer: "); n = sc.nextInt(); originalNumber = n; // reversing while( n!= 0 ) { remainder = n % 10; rev = rev * 10 + remainder; n /= 10; } // Displaying if (originalNumber == rev ) System.out.println(originalNumber + " is a palindrome."); else System.out.println(originalNumber + " is not a palindrome."); } } |
Output:
Enter an integer: 1991
1991 is a palindrome.