我想在else語句之后將代碼流重定向到“1”部分。我試圖通過創(chuàng)建循環(huán)和不同的方法來實現(xiàn)它,但我無法做到。我想要的是,當給出無效答案時會出錯,并會再次提問。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
提交
取消