我有循環設計來驗證問題的用戶輸入,它工作正常,直到我加入;無法訪問的聲明
if (userInput.charAt(0) > NUMCOLS && userInput.charAt(0) < 0);
{
System.out.println("Error, " + userInput + " is an invalid move.");
continue;
}
在此之前
if (userInput.charAt(2) !='-')
{
System.out.println("Error, " + userInput + " is an invalid move.");
continue;
}
現在,每當我嘗試編譯,我得到一個錯誤,指出這是一個可達聲明,是什麼原因造成的?
行 - 我錯了,這個是你的編譯錯誤的原因,而是你的邏輯似乎錯。這兩種情況如何同時成立? – 2010-03-05 04:51:43
其實這是我遇到的下一個問題,這是我正在測試的;如果(userInput.charAt(0)<0 && userInput.charAt(0)>(NUMCOLS + 1)) 我想要做的是創建一個跳棋遊戲,我檢查以確保玩家輸入的數字介於1到8之間,NUMCOLS是一個用來確定棋盤大小的變量(在這種情況下是7,但棋盤棋子是1-8而不是0-7,因此增加了1到NUMCOLS) 無論我輸入什麼,它總是返回false,並跳過錯誤... – Troy 2010-03-05 05:11:49
所以你想要的是userInput.charAt(0)> = 1 && userInput.charAt(0)<9) – 2010-03-05 05:13:57