我正在編寫一個課程程序,用於分析輸入的不同產品代碼。這很簡單,但我有一個問題。如果用戶輸入「E」或「e」,我試圖結束一個循環。但是,它並沒有結束循環。這是在while語句的結尾,因此將loop設置爲false應該結束它,它甚至不會輸出總數,所以我已經搞砸了。代碼是一個字符串類型。字符串問題 - Java
// Prompt the user for another company code or exit
System.out.print("Enter the company code or type 'e' to exit: ");
// Input the user's company code
code = scan.nextLine();
// Check to see if the user wants to exit
if (code == "e" || code == "E") {
// Output final statistics
System.out.print("Total valid codes: " + valid + "/n");
System.out.print("Total banned codes: " + banned);
// End the loop
loop = false;
}
任何想法?謝謝!
我看不到任何代碼迴路? –
你可以放入循環碼嗎?我想你想用「打破」而是結束循環,但我不知道你的循環是什麼樣的。 – MacGyver