Monday , February 27 2017
Home / java programs / Java Program to Check a Number is Palindrome or not ?

Java Program to Check a Number is Palindrome or not ?

Here we are going to write a program to check a number is Palindrome or not ?

Number is Palindrome or not ?

import java.util.Scanner;

public class Number_PalindromeExample {

    public static void main(String a[]) {

        int remainder, sum = 0, tempValue;
        Scanner s1 = new Scanner(System.in);
        System.out.print("Enter a value");
        int inputValue = s1.nextInt();

        tempValue = inputValue;

        while (inputValue > 0) {

            remainder = inputValue % 10;
            sum = (sum * 10) + remainder;
            inputValue = inputValue / 10;

        }

        if (tempValue == sum) {
            System.out.println("Palindrome Number");
        } else {
            System.out.println("Not a palindrome");
        }

    }
}

Output :

Enter a value 151
Palindrome Number

Enter a value
562
Not a palindrome

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Check Also

Java Program To find A Number is ArmStrong or Not ?

Here we are going to write a program to check a number is ArmStrong or …

Leave a Reply

Your email address will not be published. Required fields are marked *