Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 变量";j";无法解析为变量-二维数组_Java_Arrays_For Loop_Compiler Errors - Fatal编程技术网

Java 变量";j";无法解析为变量-二维数组

Java 变量";j";无法解析为变量-二维数组,java,arrays,for-loop,compiler-errors,Java,Arrays,For Loop,Compiler Errors,我对编程非常陌生(5天)。我从Java开始。 现在,我陷入了这个可怕的错误,我不明白,也不知道如何修复 public static void main(String[] args) { int[][] TwoDim = new int [4][3]; // <-- 1st [rows] , 2nd [columns] // TwoDim[2][1] = 10; |\|\|\| this way, we can assign number 10 to row 2,

我对编程非常陌生(5天)。我从Java开始。 现在,我陷入了这个可怕的错误,我不明白,也不知道如何修复

public static void main(String[] args) {
    int[][] TwoDim = new int [4][3];  // <-- 1st [rows]   , 2nd [columns]

    // TwoDim[2][1] = 10;  |\|\|\| this way, we can assign number 10 to row 2, column 1 , it's manual this way

    int temp = 10;

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++);
            TwoDim[i][j] = temp; // <<-- why isn't j resolved as a variable?!?!
            temp += 10;
        }
    }
}
publicstaticvoidmain(字符串[]args){

int[][]TwoDim=new int[4][3];//由于
之后的
内部循环是空的
j
仅在该循环的范围内定义,该范围是空的。使用
{
}
打开循环的块,您应该可以:

for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) { // No ; here!
        TwoDim[i][j] = temp;
        temp += 10;
    }
}
for(int i=0;i<4;i++){
对于(intj=0;j<3;j++){//No;这里!
TwoDim[i][j]=温度;
温度+=10;
}
}

for循环声明后的分号丢失;它算作for循环的主体!在适当的情况下,对内部for循环使用大括号。您还需要将要在for循环中执行的代码用大括号括起来。否则,在for循环中只会执行for循环后的第一行。