简体   繁体   English

println错误:位置类,方法println()

[英]Error wtih println: Location class,method println()

Im trying to create a printable on command promt board in order to manage to create a TicTacToe game in CMD. 我试图在命令提示符板上创建可打印的内容,以便设法在CMD中创建一个TicTacToe游戏。 Although,when i create the class for my board and my cells, Java throws an error under my print and println saying me that: 虽然,当我为我的电路板和单元格创建类时,Java在我的print和println下抛出了一个错误,告诉我:

symbol: method println()  -or- method print() .etc...

location: class board

error: cannot find symbol

whats the problem with my code? 我的代码有什么问题? Here is my whole .java file: 这是我的整个.java文件:

i just want it to compile,not to run 我只希望它编译而不运行

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

}

It compiles just by replacing print() and println() with system.out. 它仅通过用system.out替换print()和println()进行编译。 But this is too weird. 但这太奇怪了。 ACM package includes methods like println() and print() in order to make it easier. ACM软件包包括诸如println()和print()之类的方法,以使其变得更容易。 but now it is fixed. 但是现在它是固定的。 Thank you. 谢谢。

EDIT 2: in order to compile with print() and println() IT IS A NEED to have: "public class board extends Program" and NOT just "public class board" 编辑2:为了与print()和println()进行编译,需要具有:“公共类板扩展程序”,而不仅仅是“公共类板”

Try to replace println() and print() by 尝试将println()print()替换为

System.out.print();
System.out.println();

If you want to use ACM, you must have acm.jar file in your classpath and you must extend Program class in your board class like: class board extends Program{} 如果要使用ACM,则必须在类路径中包含acm.jar文件,并且必须在board级中扩展Program类,例如: class board extends Program{} acm.jar class board extends Program{}

See also : 另请参阅

Here is the corrected code: 这是更正的代码:

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

You were just missing some calls to "System.out" for the print statements. 您只是错过了一些针对打印语句的“ System.out”调用。

Change println() by 通过更改println()

System.out.print(); or   
System.out.println();

For More 更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM