当我创建一个变量并将代码包装在一个 while 循环中时,它永远不会重复。这是我尝试过的代码示例。
String repeat = "y";
Scanner keyboard = new Scanner(System.in);
while (repeat == "y"){
String word1 = "this";
String word2 = "that";
String word3 = word1 + word2;
System.out.println(word3);
for(int x = 10; x<20; x = x+1){
word3 = word1 + word3;
System.out.println(word3);
}
repeat = keyboard.nextLine();
}
无论脚本末尾的输入是什么,它都会结束。有什么帮助吗?