PROGRAM FOR PALINDROM NUMBER

Palindrome number is a number which is equal to reverse of itself.

For example 121 is a palindrome because reverse of 121 is 121, while 123 is not a palindrome in Java because reverse of 123 is 321 and 121!=321.

In this programe first step of logic is we should have to find out the modulus operation determines the remainder of the division operation of the two numbers.

The next step is we should have to divide the num value by 10.

The next step is we should have to add that remainder value with the multiplication of reverse value(initially rev=0)and 10 then we will get rev value.

The next step is in if condition that rev value exactly equale to m value(rev==m),that rev is a palindrome otherwise its not a palindrome.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package pack;
import java.util.Scanner;
public class Palindrome
{
     public static void main(String[] args)
     {
        System.out.print("Enter any Number = ");
        Scanner x=new Scanner(System.in);
        int num=x.nextInt();
        int rev=0,m,r;
        m=num;
        while(num>0)
        {
            r=num%10;
            num=num/10;
            rev=rev*10+r;  
        }
        if(rev==m)
        System.out.println("given number is palindrome");
        else
        System.out.println("given number is not palindrome");
    }
}

Output :Palindrome Number
IPPal