我有一個類的構造函數,它將模擬騎士在java中的遊覽。現在,構造函數接受起始行和列。我想知道是否有可能採取董事會規模(總行數,總列數)的方式?我對Java很陌生,不完全理解數組,所以任何幫助將不勝感激!如何使用Java構造函數實例化一個數組?
public KnightsTour(int startRow, int startCol)
{
myBoard = new int[9][9];
myCheckList = new int[9]; // myCheckList initialized with all 0
myRandomMove = new Random();
myMoveNumber = 1;
// myRow and myCol start at (1,1)
myRow = startRow;
myCol = startCol;
myBoard[myRow][myCol] = myMoveNumber; // gets the board started
}