我没有编程,我试图回到事物的摆动,这是我得到了多少。我的问题是,我如何循环第二个问题,以便如果答案除了是或否,则再次提出问题。我曾试着围绕if语句进行循环,但每当我尝试获得用户的另一个响应时,它都会告诉我不能使用变量响应来这样做。我觉得这对于我理解循环来说是一个简单的解决方案,但是我很难在这个特定的问题上进行包装,感谢您的提前。Java中的循环逻辑
import java.util.Scanner;
public class Practice {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to my simulation, please enter your name");
String name = input.nextLine();
System.out.println("Welcome " + name + " would you like to play a game?");
String response = input.nextLine();
boolean yes = new String("yes").equals(response.toLowerCase());
boolean no = new String("no").equals(response.toLowerCase());
if (yes){
System.out.println("Which game woudl you like to play?");
}else if (no){
System.out.println("Fine then, have a good day!");
}
else{
System.out.println("please enter either yes or no");
}
}
}
请勿使用'new String(“yes”)'。 '“是”'会做得很好。 – shmosel
东西的“摆动”..呃.. – Eric
@Eric但是......在这个问题上没有Swing。 – shmosel