0

私のプログラムは文字通りちょうど動いていて、それを差し込もうとしていて、安全のためにもう一度コンパイルしましたが、このエラーはありますか?

私のコードが突然動作しなくなった理由が完全にわからないため、迅速な助けが必要です:(((((((((((((

TrominoSolver.java:175: error: constructor tromino in class tromino cannot be applied to given types;
            tromino thisguy = new tromino(size, x, y);
                              ^
  required: no arguments
  found: int,int,int
  reason: actual and formal argument lists differ in length

なぜ私は突然これを手に入れたのですか?

これが私のコードです

 import java.util.*;

public class TrominoSolver {
    //create a drawing panel of width=400px and height=400px

    private int[][] board;
    private int currentNum;

    // 0<=x<size, 0<=y<size
    // create an empty tromino object of dimension size x size.
    public void tromino(int size, int x, int y) {

        int actualsize = 1;
        while (actualsize < size) actualsize*=2;     //actualsize = actualsize * 2

        //Board is power of 2
        board = new int[actualsize][actualsize];
        currentNum = 1;

        // Initialize with empty squares.
        for (int i=0; i<actualsize; i++) {
            for (int j=0; j<actualsize; j++) {
                board[i][j] = 0;
            }
        }

        // Hole in board
        board[x][y] = -1;
    }

    // call for recursive method.
    public void tile() {
        tileRec(board.length, 0, 0);
    }

    private void tileRec(int size, int topx, int topy) {

        // fill in your one tromino...
        if (size == 2) {

            // Fill in the one tromino. The hole is identified by a
            // -num, don't fill in that one square.   
            for (int i=0; i<size; i++) 
                for (int j=0; j<size; j++)
                    if (board[topx+i][topy+j] == 0)
                        board[topx+i][topy+j] = currentNum;

            // Advance to the next tromino.
            currentNum++;
        }

        // Recursive case...
        else {

            // Find coordinates of hole
            int yesx=topx, yesy=topy;

            for (int x=topx; x<topx+size; x++) 
                for (int y=topy; y<topy+size; y++)
                    if (board[x][y] != 0) {
                        yesx = x;
                        yesy = y;
                    }

            // Hole in upper left quadrant.     
            if (yesx < topx + size/2 && yesy < topy + size/2) {

                // Recursively tile upper left quadrant.
                tileRec(size/2, topx, topy);

                // Fill in middle tromino
                board[topx+size/2][topy+size/2-1] = currentNum;
                board[topx+size/2][topy+size/2] = currentNum;
                board[topx+size/2-1][topy+size/2] = currentNum;

                // Advance to the next tromino
                currentNum++;

                // make other recursive calls.
                tileRec(size/2, topx, topy+size/2);
                tileRec(size/2, topx+size/2, topy);
                tileRec(size/2, topx+size/2, topy+size/2);

            }

            // Hole in upper right quadrant
            else if (yesx < topx + size/2 && yesy >= topy + size/2) {

                // Recursively tile upper right quadrant.
                tileRec(size/2, topx, topy+size/2);

                // Fill in middle tromino
                board[topx+size/2][topy+size/2-1] = currentNum;
                board[topx+size/2][topy+size/2] = currentNum;
                board[topx+size/2-1][topy+size/2-1] = currentNum;

                // Go to the next tromino
                currentNum++;

                // make other recursive calls.
                tileRec(size/2, topx, topy);
                tileRec(size/2, topx+size/2, topy);
                tileRec(size/2, topx+size/2, topy+size/2);

            }

            // Hole in bottom left quadrant
            else if (yesx >= topx + size/2 && yesy < topy + size/2) {

                // Recursively tile bottom left quadrant.
                tileRec(size/2, topx+size/2, topy);

                // Fill in middle tromino
                board[topx+size/2-1][topy+size/2] = currentNum;
                board[topx+size/2][topy+size/2] = currentNum;
                board[topx+size/2-1][topy+size/2-1] = currentNum;

                // Go to the next tromino
                currentNum++;

                // make other recursive calls.
                tileRec(size/2, topx, topy);
                tileRec(size/2, topx, topy+size/2);
                tileRec(size/2, topx+size/2, topy+size/2);
            }
            else {

                // Recursively tile bottom right quadrant.
                tileRec(size/2, topx+size/2, topy+size/2);

                // Fill in middle tromino
                board[topx+size/2-1][topy+size/2] = currentNum;
                board[topx+size/2][topy+size/2-1] = currentNum;
                board[topx+size/2-1][topy+size/2-1] = currentNum;

                // Go to the next tromino
                currentNum++;

                // Now we can make our three other recursive calls.
                tileRec(size/2, topx+size/2, topy);
                tileRec(size/2, topx, topy+size/2);
                tileRec(size/2, topx, topy);
            }

        } 

    } 

    // Print out latest object
    public void print() {

        for (int i=0; i<board.length; i++) {
            for (int j=0; j<board[i].length; j++)
                System.out.print(board[i][j] + "\t");
            System.out.println();
        }
    }
    public static void main(String[] args) {

        Scanner stdin = new Scanner(System.in);

        // user input...
        int size = stdin.nextInt();
        int x = stdin.nextInt();
        int y = stdin.nextInt();

        tromino thisguy = new tromino();
        thisguy.tile();

        // Print out the tromino board.
        thisguy.print();

    }
}
4

3 に答える 3

0

エラーの原因は

trominoあなたのコンストラクターではなく、あなたのメソッドです。コンストラクターには戻り値の型がありません。

引数のないコンストラクター (デフォルトで提供) を使用することも、引数を使用して 1 つ以上のコンストラクターを明示的に宣言することもできます。

このような引数でコンストラクターを宣言できます

public TrominoSolver(int size,int x,int y) {
  this.size=size;
  this.x=x;
  this.y=y;
}

size , x and yクラスのメンバーが提供されますTrominoSolver

このコンストラクタを使用して、このようにオブジェクトを作成できます

TrominoSolver trominoSolver = new TrominoSolver(3,2,1);

参照を使用してメソッドを呼び出しますtrominoSolver

于 2013-11-12T08:20:39.897 に答える
0

コンストラクターの宣言は、メソッドの宣言と似ていますが、クラスの名前を使用し、戻り値の型がないことを除けば、記述するpublic void tromino(int size, int x, int y) {代わりに、次のようにpublic TrominoSolver(int size, int x, int y) {クラスをインスタンス化できます。 TrominoSolver thisguy = new TrominoSolver(size, x, y);

于 2013-11-12T08:13:04.253 に答える