This program runs without throwing any exceptions, but regardless of the input the result is always the same: ""blank" is a palindrome." Every single time the input is a palindrome I was just wondering if anyone had any advice as to why this is happening? Here is the code for the program:
class Palindrome
{
public static void main(String args[])
{
int num = 0;
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int dig5 = 0;
boolean digits = true;
retrieveInput(num);
check(num,dig1,dig2,dig3,dig4,dig5);
display(digits,num);
}
public static int retrieveInput(int num)
{
String number;
number = JOptionPane.showInputDialog("Enter A Five Digit Number.");
num = Integer.parseInt(number);
while(num < 9999 || num > 99999)
{
JOptionPane.showMessageDialog(null, num + " Is Not A Five Digit Number",
"ERROR", JOptionPane.ERROR_MESSAGE);
number = JOptionPane.showInputDialog("Enter A Five Digit Number.");
num = Integer.parseInt(number);
}
return num;
}
public static boolean check(int num,int dig1,int dig2,int dig3,int dig4,int dig5)
{
boolean digits;
dig1 = num / 10000;
dig2 = num % 10000 / 1000;
dig3 = num % 10000 % 1000 / 100;
dig4 = num % 10000 % 1000 % 100 /10;
dig5 = num % 10000 % 1000 % 100 % 10 / 1;
if (dig1 == dig5 && dig2 == dig4)
digits = true;
else
digits = false;
return digits;
}
public static void display(boolean digits, int num)
{
num = retrieveInput(num);
if (digits = false)
JOptionPane.showMessageDialog(null, num + " is a palindrome");
else
JOptionPane.showMessageDialog(null, num + " is not a palindrome");
}
}