I have a question to input a 5 digit integer. The program will output if it is a palindrome or not. And it will display "not a palindrome" if integer is not a palindrome.
But the problem is that the program crash whenever i input a less than 5 digit integer. Else everything is fine. The program even output "not a 5 digit number" when i input an integer with more than 5 digit.
Here is my code.
String input1;
int number, number2, a, b, d, e;
input1 = JOptionPane.showInputDialog("Enter 5 digit number");
a = input1.charAt(0);
b = input1.charAt(1);
d = input1.charAt(3);
e = input1.charAt(4);
number2 = input1.length();
number = Integer.parseInt(input1);
if (number2 >= 6) {
JOptionPane.showMessageDialog(null, "Not a 5 digit number");
}
if (number2 <= 4) {
JOptionPane.showMessageDialog(null, "Not a 5 digit number");
}
if ((a == e) && (b == d)) {
JOptionPane.showMessageDialog(null, "Palindrome");
} else {
JOptionPane.showMessageDialog(null, "Not a palindrome");
}