我正在编写一个课程程序,用于分析输入的不同产品代码。这很简单,但我有一个问题。如果用户输入“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