public class Matrix {
private int row=0;
private int col=0;
private int [] [] array = null;
public Matrix () {}
public Matrix (int row, int col){
this.row=row;
this.col=col;
array = new int [row][col];
}
public void showMatrix(){
for(int i = 0 ; i < row; i++){
for(int j = 0; j < col; j++){
array[i][j]=(int)(Math.random()*20)+1;
System.out.print(array[i][j]+"\t");
}
System.out.println();
}
}
public static void main(String[] arge) {
Matrix m1 = new Matrix(3,5);
m1.showMatrix();
System.out.println;
Matrix m2 = new Matrix(10,20);
m2.showMatrix();
}
}
用个二维数组就可以了,何必这么复杂。