我是一个初学者,我正在尝试编写井字游戏,但我遇到了我不明白的错误

时间:2019-10-05 03:05:35

标签: java compiler-errors dereference

我遇到的错误是“找不到符号”。在“ tic”之后的时期       p1L = tic.nextChar();

,并且在“ p1L”之后的时间段也“不能取消引用” p1L = p1L.equalsIgnoreCase(p1L);

我不确定这意味着什么或如何解决它。

正如一些同学建议的那样,我试图在循环中重新定义扫描仪,但这似乎不起作用或存在问题

Scanner tic = new Scanner(System.in);
Scanner tac = new Scanner(System.in);

for (int i = 0; wins || i == 9;i++) {
  tic = new Scanner(System.in);
  tac = new Scanner(System.in);

  table = line1+"/n"+A+"/n"+line2+"/n"+B+"/n"+line3+"/n"+C;

  System.out.println(table);//show table

  System.out.println("Enter Line A,B, or C for X (Player1)");
  p1L = tic.nextChar();
  p1L = p1L.equalsIgnoreCase(p1L);
  System.out.println ("Enter Row 1,2, or 3 for X (Player1)");
  p1R = tic.nextInt();

我希望输出以tic-tac-toe表开头,然后请求输入。例如 “为X(Player1)输入A,B或C行”

2 个答案:

答案 0 :(得分:0)

Scanner 对象中没有称为 nextChar()的方法。您是说 nextLine()吗?

我不知道 p1L 中的对象类型。但是我可以说的是, equalsIgnoreCase()并不是该类的一种方法。

参考:https://www.w3schools.com/java/java_user_input.asphttps://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

答案 1 :(得分:0)

例如:

Scanner tic = new Scanner(System.in); // use Standard Input for reading data (when the user writes to console)
Scanner tac = new Scanner(System.in); // delete because you have a scanner

for (int i = 0; wins || i == 9;i++) {
  tic = new Scanner(System.in); // delete because you have a Scanner
  tac = new Scanner(System.in); // delete because you have a Scanner

  table = line1+"/n"+A+"/n"+line2+"/n"+B+"/n"+line3+"/n"+C;

  System.out.println(table);//show table

  System.out.println("Enter Line A,B, or C for X (Player1)");
  p1L = tic.nextChar(); // delete, because method does not exist,
  p1L = p1L.equalsIgnoreCase(p1L); // delete, because method exist only data type String (text)
  p1L = tic.nextLine(); // read text
  p1L = p1L.toUpperCase() // make for "a" -> "A", for "A" -> "A"
  System.out.println ("Enter Row 1,2, or 3 for X (Player1)");
  p1R = tic.nextInt();