我正在编写一个程序,如果用户输入字符串 "end",则应该关闭控制台。但是即使用户输入了 "end",程序始终执行 else 循环。我想知道为什么程序没有进入循环的 if 部分并关闭。
Scanner scan = new Scanner(System.in);
while(true)
{
String num = scan.nextLine();
if(num == "end")
{
System.exit(0);
}
else
{
System.out.println("hi");
}
}