Java program to check the given number is Palindrome or not


Program

package com.candidjava;

import java.util.Scanner;

public class PalindromeNumber
{
	public static void main(String args[])
	{
		int n, pal, Rev = 0, r;
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the number to check palindrome number or not");
		n = sc.nextInt();
		pal = n;

		while (n > 0)
		{
			r = n % 10;
			Rev = Rev * 10 + r;
			n = n / 10;

		}

		if (Rev == pal)
		{
			System.out.println(" The given no is  palindrome "+ Rev);
		}
		else
		{
			System.out.println("The given no is not palindrome " + Rev);
		}
	}

}

Output

Enter the number to check palindrome number or not

121

 The given no is  palindrome 121

Enter the number to check palindrome number or not

123

The given no is not palindrome 321



Related Post

Comments


©candidjava.com