首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >错误wtih : Location类,方法println()

错误wtih : Location类,方法println()
EN

Stack Overflow用户
提问于 2014-02-07 03:23:30
回答 3查看 122关注 0票数 1

我试图创建一个可打印的命令promt板,以设法创建一个TicTacToe游戏在CMD。尽管在为我的板和单元格创建类时,Java在我的print和println中抛出了一个错误,并告诉我:

代码语言:javascript
复制
symbol: method println()  -or- method print() .etc...

location: class board

error: cannot find symbol

我的代码有什么问题?以下是我的整个.java文件:

我只想让它编译,而不是运行

代码语言:javascript
复制
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()进行编译,IT需要:“公共类板扩展程序”,而不仅仅是“公共类板”

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-02-07 03:33:17

以下是修正后的代码:

代码语言:javascript
复制
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)) {
                   System.out.print("|");   // print vertical partition
               }
            }
           System.out.println("");
           if (row !=(ROWS-1)) {
               System.out.println("-----------");
           }
        }
    System.out.println();
    }


    public void printCell(int content) {
         if (content == 0)  {System.out.print("   ");}
    }
}

对于print语句,您只是忽略了对"System.out“的一些调用。

票数 1
EN

Stack Overflow用户

发布于 2014-02-07 03:30:58

尝试将println()print()替换为

代码语言:javascript
复制
System.out.print();
System.out.println();

如果要使用ACM,则必须在类路径中包含acm.jar文件,并且必须在board类中扩展Program类,如:class board extends Program{}

也见

票数 3
EN

Stack Overflow用户

发布于 2014-02-07 03:35:47

println()改为

代码语言:javascript
复制
System.out.print(); or   
System.out.println();

对于更多

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21618684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档