"error: class expected" for two-dimensional array nested 'for' loop
"error: class expected" for two-dimensional array nested 'for' loop
public class TwoDmArrayPractice {
public TwoDmArrayPractice() {
}
public static void main(String[] args)
{
double[][] data1 = new int[4][5];
for(int i=0; i<data1.length; i++)
{
for(int j=0; j< data1[].length; j++)
{
data1[i][j] = j;
}
}
}
}
大家好,我正在摆弄二维数组,使用 'for' 循环来填充数组
我了解这个嵌套的 for 循环是如何工作的 我只是在包含第二个 'for' 循环参数的行上不断收到错误。我到处搜索类似的问题,但无济于事。
在你的第二个 for 循环中尝试这个:
for(int j=0; j< data1[i].length; j++)
public class TwoDmArrayPractice {
public TwoDmArrayPractice() {
}
public static void main(String[] args)
{
double[][] data1 = new int[4][5];
for(int i=0; i<data1.length; i++)
{
for(int j=0; j< data1[].length; j++)
{
data1[i][j] = j;
}
}
}
}
大家好,我正在摆弄二维数组,使用 'for' 循环来填充数组 我了解这个嵌套的 for 循环是如何工作的 我只是在包含第二个 'for' 循环参数的行上不断收到错误。我到处搜索类似的问题,但无济于事。
在你的第二个 for 循环中尝试这个:
for(int j=0; j< data1[i].length; j++)