我正在嘗試編寫一個If或If-Else語句,用於在出現提示時未輸入整數值時保護程序。我不斷收到錯誤消息:'.class'的預期。If or If-Else Statement Error
System.out.println("Type the name of your destination: ");
destination = keyboard.nextLine();
System.out.print(destination + " is how many miles away?");
miles = keyboard.nextInt();
if (miles != int);
{
System.out.println(miles + " is not valid. I will use 100 for the number of miles.");
}
什麼是錯誤信息? – 2013-03-05 03:27:22
爲什麼不使用Integer.parseInt()?如果它不是一個有效的整數,則會拋出NumberFormatException。 – Dhinakar 2013-03-05 03:29:08