I'm getting an error at the line
else break;
I think it might have to do with the location of the "{}"
public class Palindrome {
private static String number;
public static void main(String[] args) {
display();
}
private static int getUserInput() {
int inputNumber = 0;
String answer = JOptionPane.showInputDialog(null, "Please enter a five digit number","Enter a number");
inputNumber = Integer.parseInt(answer);
if(number.length() !=5 ){
JOptionPane.showMessageDialog(null,"Please enter a 5 digit number!","Try again",
JOptionPane.PLAIN_MESSAGE);
else break;
}
return inputNumber;
}
private static boolean check(){
int inputNumber = getUserInput();
int number = inputNumber;
int[] myArray = new int[5];
for (int i = 0; i < myArray.length; i++) {
myArray[i] = (int) (number /(Math.pow(10,i)) % 10);
}
if(myArray[0] == myArray[4] && myArray[1] == myArray[3])
return true;
else
return false;
}
public static boolean display(){
if (check() == true) {
JOptionPane.showMessageDialog(null, "This number is a Palindrome",
"Excellent!",JOptionPane.INFORMATION_MESSAGE);
} else
JOptionPane.showMessageDialog(null,
"Number is not a Palindrome!",
"Sorry",
JOptionPane.ERROR_MESSAGE);
return false;
}
}
}
Thanks