我想在一个方法(函数?对象?顺便问一下 - 这些单词之间有什么区别?)中创建一个数组,然后在另一个方法中使用它的长度(我还将在其他地方使用它)。 我的老师告诉我不需要返回数组,因为我只是修改它的位置,所以数组并没有被销毁或者其他什么。如果我在主函数中声明,那么我就无法在获取大小输入后调整其大小(我不认为可以吧?)
有人听得懂吗?
public class Update {
public static void main(String[] args) {
System.out.println("This program will simulate the game of Life.");
createMatrix();
// birthAndLive();
printMatrix();
}
public static void createMatrix() {
Scanner console = new Scanner(System.in);
System.out.println("Please input the size of your board.");
System.out.println("Rows:");
final int rows = console.nextInt();
System.out.println("Columns:");
final int columns = console.nextInt();
System.out.println("Please enter a seed:");
final long seed = console.nextLong();
boolean[][] board = new boolean[rows][columns];
Random seedBool = new Random(seed);
}
public static void printMatrix() {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[i].length; j++) {
if (board[i][j] == false)
System.out.print(" - ");
else
System.out.print(" # ");
}
System.out.println();
}
}