今天我在搞乱,我试图创建一个多项选择测试。我做到了这一点,它的工作原理。不过我想知道,如果用户回答错误,我将如何让它重复这个问题?如果有人可以帮助我,那就太好了!谢谢!
import java.util.Scanner;
public class multipleChoiceTest {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.println("What color is the sky?");
System.out.println("A. Blue");
System.out.println("B. Green");
System.out.println("C. Yellow");
System.out.println("D. Red");
String userChoice = myScanner.nextLine();
if (userChoice.equalsIgnoreCase("a")) {
System.out.println("You're right!");
} else {
System.out.println("You're wrong! Try Again.");
}
}