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

问题描述 投票:0回答:2

我遇到的错误是“找不到符号”。在“ 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();

我希望输出以井字游戏表开始,然后是我的输入请求。例如“为X(Player1)输入A,B或C行”

java compiler-errors dereference
2个回答
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

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();
© www.soinside.com 2019 - 2024. All rights reserved.