我在該行收到錯誤如果在Java代碼中的錯誤否則
else break;
我認爲它可能與「{}」
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;
}
}
}
感謝
的位置做
如果您縮進代碼,您會發現修復這些錯誤要容易得多 - 您應該發現IDE願意爲您自動執行此操作。 – 2011-03-09 18:02:46