Menu



Java palindrome program (with a scanner class input from keyboard)


java-Palindrome.java

import java.util.Scanner;
public class Palindrome
{
public static void main(String[] args)
{
System.out.println("Enter a number : ");
int num = new Scanner(System.in).nextInt();
int number=num;
int rev=0;
while (number != 0)
{
int rem = number % 10;
rev = rev * 10 + rem;
number = number / 10;
}
if(num == rev)
System.out.println("it is a Palindrome number");
else
System.out.println("it is Not a Palindrome number");
}
}

Java palindrome program of a no (input through program)

class Palindrome
{
public static void main(String args[])
{
int rem,sum=0,rev;
int n=454;//It is the number variable to be checked for palindrome
rev=n;
while(n>0)
{
rem=n%10; //getting remainder
sum=(sum*10)+rem;
n=n/10;
}
if(rev==sum)
System.out.println("It is a palindrome number ");
else
System.out.println("It is not a palindrome number");
}
}

Output

palindrome