我试图在命令提示板上创建可打印的内容,以便设法在 CMD 中创建井字游戏。虽然,当我为我的板子和单元格创建类时,Java 在我的 print 和 println 下抛出一个错误,告诉我:
symbol: method println() -or- method print() .etc...
location: class board
error: cannot find symbol
我的代码有什么问题?这是我的整个 .java 文件:
我只是想让它编译,而不是运行
import acm.program.*;
public class board {
private static final int ROWS=3;
private static final int COLS=3;
private int[][] board1 = new int[ROWS][COLS];
//constructor
public board() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
board1[i][j]=0;
printBoard();
}
}
}
public void printBoard() {
for(int row =0; row<ROWS; row++) {
for (int col=0; col<COLS; col++) {
printCell(board1[row][col]);
if (col != (COLS-1)) {
print("|"); // print vertical partition
}
}
println();
if (row !=(ROWS-1)) {
println("-----------");
}
}
println();
}
public void printCell(int content) {
if (content == 0) {print(" ");}
}
}
它只需将 print() 和 println() 替换为 system.out 即可编译。但这太奇怪了。ACM 包包括 println() 和 print() 等方法,以使其更容易。但现在它是固定的。谢谢你。
编辑 2:为了使用 print() 和 println() 进行编译,需要:“公共类板扩展程序”而不仅仅是“公共类板”