We can reverse the number and check if they are equal.
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 |
public static void main(String args[]){ int x = 345; int y = 343; int tempx=x; int tempy=y; int rx = 0; int ry = 0; while(tempx!=0 && tempy!=0){ rx *=10; ry *=10; rx = rx + tempx%10; ry = ry + tempy%10; tempx /=10; tempy /=10; } if(x == rx) System.out.println("x is Palindrome Number"); else System.out.println("x is not a Palindrome number"); if(y == ry) System.out.println("y is Palindrome Number"); else System.out.println("y is not a Palindrome Number"); } |
Output
1 2 |
x is not a Palindrome number y is Palindrome Number |
Discussion
Above program is just show of logic and for generic program you need to change few things.
Compiled with JDK 9