# Answer to Question #6712 in Java | JSP | JSF for Ramero

Question #6712

Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "The number is a palindrome." If it is not then print "The number is not a palindrome"

We have to use an Array

We have to use an Array

Expert's answer

public class IsPalindrome {

public static void main(String [] args){

Scanner keyboard = new Scanner(System.in);

int [] array = new int [5];

while(true){

System.out.println("Input number: ");

int n = Integer.valueOf(keyboard.next()).intValue();//read n

if( (n >= 10000 ) && (n <= 99999)){ //if it's 5 digits number

for(int i = 0; i < 5; i++){

array[i] = i % 10;

i /= 10;

}

if ( (array[0] == array[4]) && (array[1] == array[3])){

System.out.println("The number is a palindrome.");

} else {

System.out.println("The number is not a palindrome.");

}

} else {

System.out.println("ERROR! It's not 5 digits number.");

}

}

}

}

public static void main(String [] args){

Scanner keyboard = new Scanner(System.in);

int [] array = new int [5];

while(true){

System.out.println("Input number: ");

int n = Integer.valueOf(keyboard.next()).intValue();//read n

if( (n >= 10000 ) && (n <= 99999)){ //if it's 5 digits number

for(int i = 0; i < 5; i++){

array[i] = i % 10;

i /= 10;

}

if ( (array[0] == array[4]) && (array[1] == array[3])){

System.out.println("The number is a palindrome.");

} else {

System.out.println("The number is not a palindrome.");

}

} else {

System.out.println("ERROR! It's not 5 digits number.");

}

}

}

}

## Comments

## Leave a comment