-7
是否有可能有行数不同的列数的数组?行可以有不同的列数?
是否有可能有行数不同的列数的数组?行可以有不同的列数?
是的,这是可能的,我这里是通过他们迭代
public static void main(String[] args) {
int[][] numbers = new int[][] { { 1, 2, 3 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4, 5 } };
for(int i = 0; i<numbers.length;i++) {
for(int j = 0; j < numbers[i].length; j++) {
System.out.print(numbers[i][j]);
}
System.out.println("");
}
}
输出:
123
1234
12345
是的,你可以有不同的列数为每行。
data_type [][] array = new data_type[row][]
array[0] = new data_type[size1]
array[1] = new data_type[size2]
P.S:你为什么不尝试你的系统上,问这样的问题了。
P.P.S:这里我假设row >=2
。
你为什么不尝试呢? – Eran
@Eran我刚刚更新了问题以帮助他人 – VSB