我想用一组特定的数字填充 Java 中的二维数组。
我的样本数组集:{{7,-4},{8,-2},{9,-1}}
如果不这样做,如何加载数组?
int[][] x = new int[3][2];
x[0][0] = 7;
x[0][1] = -4;
x[1][0] = 8;
x[1][1] = -2;
x[2][0] = 9;
x[2][1] = -1;
此外,我认为我可以做到这一点,但我得到“错误:表达的非法开始”。
class Alpha {
int[][] x;
public Alpha () {
x = new int[3][];
x[0] = {7,-4}; <== line where error is located
}
}