我想在else语句之后将代码流重定向到“1”部分。我试图通过创建循环和不同的方法来实现它,但我无法做到。我想要的是,当给出无效答案时会出错,并会再次提问。import java.util.Scanner;public class OddsAndEvens { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Let’s play a game called “Odds and Evens”"); System.out.println("What is your name?"); String name = input.next(); // 1 <------------------------ System.out.println("Hello " + name + " which one do you choose? (O)dds or (E)vens?"); String oe = input.next(); if (oe.equalsIgnoreCase("e")) { System.out.println(name + " has picked evens! The computer will be odds."); } if (oe.equalsIgnoreCase("o")) { System.out.println(name + " has picked odds! The computer will be evens."); } else { System.out.println("You have typed an invalid answer."); } }}
添加回答
举报
0/150
提交
取消