0
需要我的代碼的一些幫助。我試圖修改書面代碼,要求用戶輸入「是」或「否」,以便循環繼續。如果用戶輸入「yes」或「no」以外的任何內容,我應該使用素數讀取和while循環來顯示錯誤消息。需要幫助修改輸入驗證和錯誤消息的代碼
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//declare local variables
String endProgram = "no";
boolean inputValid;
while (endProgram.equals("no")) {
resetVariables();
number = getNumber();
totalScores = getScores(totalScores, number, score, counter);
averageScores = getAverage(totalScores, number, averageScores);
printAverage(averageScores);
do {
System.out.println("Do you want to end the program? Please enter yes or no: ");
input.next();
if (input.hasNext("yes") || input.hasNext("no")) {
endProgram = input.next();
} else {
System.out.println("That is an invalid input!");
}
}
while (!(input.hasNext("yes")) || !(input.hasNext("no")));
}
}
這是我迄今爲止,但它不能正常工作我想看看錯誤是什麼。 –