Find if the given number is palindrome number or not. - Java Language Basics

Java examples for Language Basics:int

Description

Find if the given number is palindrome number or not.

Demo Code


public class Main {
 
        public static void main(String[] args) {
                int numbers[] = new int[]{121,13,34,11,22,54};
                for(int i=0; i < numbers.length; i++){
                       /*  w ww .  j a v  a2s  .c om*/
                        int number = numbers[i];
                        int reversedNumber  = 0;
                        int temp=0;
                       
                        //reverse the number
                        while(number > 0){
                                temp = number % 10;
                                number = number / 10;
                                reversedNumber = reversedNumber * 10 + temp;
                        }
                       
                        if(numbers[i] == reversedNumber)
                                System.out.println(numbers[i] + " is a palindrome number");
                        else
                                System.out.println(numbers[i] + " is not a palindrome number");
                }
               
        }
}

Result


Related Tutorials