我这里有两个代码块.一个扫描仪正确地等待用户输入,另一个扫描仪正好通过它并且调用nextInt()返回一个NoSuchElementException.这是有效的块:
public void startGame() {
out.println("Player1: 1 for dumb player, 2 for smart player, 3 for human player.");
Scanner scan = new Scanner(System.in);
p = scan.nextInt();
if (p == 1)
p1 = new DumbPlayer("ONE");
if (p == 2)
p1 = new SmartPlayer("ONE");
else
p1 = new HumanPlayer("ONE");
out.println("Player2: 1 for dumb player, 2 for smart player, 3 for human player.");
p = scan.nextInt();
if (p == 1)
p2 = new DumbPlayer("TWO");
if (p == 2)
p2 …Run Code Online (Sandbox Code Playgroud)