大家好,我试图用这段代码退出一个循环,但在它结束之前它仍然会打印出我不想要的行:
do {
System.out.println("Would you like to change one of the numbers (y/n)?");
choice = kb.next().charAt(0);
System.out.println("Please enter the index of the number you want to change:");
indexChange = kb.nextInt();
System.out.println("Please enter the number you want to change:");
changedIndex = kb.nextInt();
elements[indexChange - 1] = changedIndex;
for (int i = 0; i < elements.length; i++)
System.out.println(index[i] + elements[i]);
} while (choice != 'n');
这两行在循环结束之前仍然打印出来:“请输入您要更改的号码:”&“请输入您要更改的号码:”。你们中的任何人都可以帮助解决这个错误吗?