Number Palindrome in Java
Here, you will learn and get the program code to check Number palindrome in Java programming.
A number palindrome is a number that reads the same forward and backward. For example, the number 1221 is a palindrome because it reads the same forward and backward.
Program for Number Palindrome in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.Scanner; public class PalindromeNumber { public static void main(String[] args) { int num,r, num2,revNum = 0; System.out.println("Enter a number : "); Scanner in = new Scanner(System.in); num = in.nextInt(); num2 = num; while (num != 0) { r= num % 10; revNum = revNum * 10 + r; num /= 10; } if (num2 == revNum) System.out.println(num2 + " is a palindrome Number."); else System.out.println(num2 + " is not a palindrome Number."); } } |
Output
Check out our other Java Programming Examples