# Write a palindrome number program in java

First we know that,what is palindrome number ?

palindrome number is a number when it reverse value must be same.

Example, suppose number=121,when reverse 121 then value will be 121. ie 121 is palindrome number.

Example,suppose number=123,when reverse 123 then value will be 321.ie 123 is not palindrome number.

Let’s Start

{

public static void main(String[] arg)

{
int remain,sum=0,palindrome;

int number=121;//Here i have taken number to check palindrome or not

palindrome=number;

while(number>0)

{
remain=n%10;

sum=sum*10+remain;

number=number/10;

}

if(palindrome==sum)

{

System.out.println(“Number is palindrome”);

}

else

{
System.out.println(“Number is not palindrome”);

}

}

}

Output:

Number is palindrome

Let’s Start Execution the Program

Here number=121

1 First i stored the “number” in the “palindrome” ie palindrome=number.

2.Check “number>0” ie 121>0

3.Find out remainder ie remain=121%10=1.

4.Find out sum ie sum=sum*10+remain=0*10+1=1//initiallly sum=0

5.Divide the number by 10 ie 121/10=12 ie number=12

6.Repeat step 2 to 5.

7.when you will repeat 2 to 5 step then Result would be like this

Again check ,number>0(Here number=12)

remain=12%10=2

sum=1*10+2=10+2=12

number=12/10=1

Again check,number>0(Here number=1)

remain=1%10=1

sum=12*10+1=120+1=121

number=1/10=0

Again check,number>0(Here number=0) ie 0>0 that is condition false

so Here sum=121 and and we stored the 121 in palindrome variable ie palindrome=121.

that means,(sum==palindrome) ie (121==121)

So,121 is palindrome number.

#### sumankumar80

Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar