Check a number is Palindrome or not in JAVA programming


//Check a given number is Palindrome or Not..........


package SolveProblem;

import java.util.Scanner;

public class PalindromeNumber {

    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
        int n;
        System.out.println("Enter the number you want to check is Palindrome or not : ");
        n=myScanner.nextInt();
       
        int num;
        num=n;
        int remainder,sum=0;
        while(num!=0){
            remainder=num%10;
            sum=sum*10+remainder;
            num=num/10;
        }
        if(sum==n){
            System.out.println(n+" is Palindrome");
        }else {
            System.out.println(n+ " is Not Palindrome");
        }
    }

}

//Enter the number you want to check is Palindrome or not :
//22
//22 is Palindrome

//Enter the number you want to check is Palindrome or not :
//25
//25 is Not Palindrome

No comments:

Post a Comment