FaltuTech.Club : Fane of Advanced Logical Thriving Utopian Technical Club

Check if Number is Palindrome Number Using Java

Check if Number is Palindrome Number Using Java

We can reverse the number and check if they are equal.



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


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