我正在为我的入门级编程课程做的一个小程序有一个小问题。
这个循环无限重复,我似乎无法弄清楚为什么。我怀疑 do 循环中的 while 循环存在某种冲突,这导致循环不断重复。这是代码: import java.util.*;
公开课秘密答案
{
public static void main(String [ ] args)
{
final char answer = ('r');
String input;
Scanner sc = new Scanner(System.in);
do
{
System.out.println("What is your guess?");
input = sc.next();
while(!input.equals("stop")) //If the user doesn't want to stop, continue
{
if(input.contains(""+answer)) //If the input contains the answer, print the following statement
{
System.out.println("Your input contained the secret letter");
}
else //If the input doesn't contain the answer, print the following statement
{
System.out.println("Your input does not contain the secret letter");
}
}
}
while(!input.equals("stop")); //loop the program if the input is not equal to 'stop'
}
}