0

当我编译我的程序时,我收到一条错误消息,

找不到标志

符号:变量 myInput

地点:类骰子游戏

我查看了我的代码,似乎在读取行中找不到错误。这是什么意思?为什么会出现这个错误?

import java.io.*;
import java.lang.*;
import java.util.*;

public class diceGame
{
  public static void main(String[] args) throws IOException {

    pairOfDice dice;

    dice = new pairOfDice();

    playerGame player;

    player = new playerGame();

    int rollCount = 0;

    int holdB = 0;
    do {
      dice.roll();    // Roll the first pair of dice.
      System.out.println("Dice 1: " + dice.getDiceA() + "\n" + "Dice 2: " + dice.getDiceB() + "\n" + "The total is: " + dice.getTotal());
      System.out.println("Do you want to hold the value of the dice? Press 0 to hold none/ 1 to hold die 1/ 2 to hold die 2/ 3 to hold both");
      String hold = myInput.readLine();
      int holdA = Integer.parseInt(hold);
      if (holdA == 0){
      }
      if (holdA == 1){
        player.getHoldA();
        player.setHoldA(dice.getDiceA());
        System.out.println("Value of dice A is held");
      }
      if (holdA == 2){
        player.setHoldB(dice.getDiceB());
        System.out.println("Value of dice B is held");
      }
      if (holdA == 3){
        player.setHoldA(dice.getDiceA());
        System.out.println("Value of dice A is held");
        player.setHoldB(dice.getDiceB());
        System.out.println("Value of dice B is held");
        break;
      }
      rollCount++;
    }
    while (dice.getTurns() <= 3);
  }
}
4

1 回答 1

2

这意味着在这条线上:

String hold = myInput.readLine();

它不知道是什么myInput,因为您从未定义过它。

很可能您想添加一个BufferedReaderaround System.in,然后从中读取:

BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String nextLine = input.readLine();
于 2013-10-02T21:43:06.667 回答