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



我得到的错误是"找不到符号"。 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 的 A、B 或 C 行(玩家 1(">

在 Scanner对象中没有名为nextChar((的方法。你是说nextLine((

而且我不知道p1L中的对象是什么类型的。但我能说的是,equalsIgnoreCase((不是那种任何类的方法。

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

例如:

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();

最新更新