我想詢問用戶是否要繼續輸入號碼添加到了總價值循環不承認一個不斷變化的變量
int total=0;
char letter='y';
while (letter == 'y');
{
Scanner userInput = new Scanner (System.in);
System.out.println("Input your number");
int number = userInput.nextInt();
total=number+total;
Scanner userInput1 = new Scanner (System.in);
System.out.println("Would you like to continue? Input y/n");
char letter = userInput1.next().charAt(0); //**This is where there is an error**
}
System.out.println("The total of all the numbers inputted is "+total);
}
}
沒有解決我被卡住的問題,但擺脫了最後的錯誤標誌。謝謝 – Destroycontract
你有什麼問題?我測試了我上面寫的代碼,當結果不是'y'時它會中斷。另外,編輯添加一個點。 – SOFe
@Pemapmodder我upvoted 3你的不同答案upvote我太男人:P –