Java Program to Check Palindrome Number in Java

 import java.util.Scanner;


public class PalindromeNumber {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);


        System.out.print("Enter an integer number: ");

        int original = sc.nextInt();


        int reversed = 0;

        int temp = original;


        while (temp != 0) {

            int digit = temp % 10;     // get last digit

            reversed = reversed * 10 + digit;  // build reversed number

            temp = temp / 10;          // remove last digit

        }


        if (original == reversed) {

            System.out.println(original + " is a Palindrome number");

        } else {

            System.out.println(original + " is not a Palindrome number");

        }


        sc.close();

    }

}


Comments

Popular posts from this blog

Create a JSP page to accept a number from an user and display it in words: Example: 123 – One Two Three. The output should be in red color.

Write a SERVLET application to accept username and password, search them into database, if found then display appropriate message on the browser otherwise display error message.

Write a JSP program to accept the details of Account (ANo, Type, Bal) and store it into database and display it in tabular form. (Use PreparedStatement interface)