2d数组中的循环,java中已有2个循环

2d数组中的循环,java中已有2个循环,java,arrays,2d,Java,Arrays,2d,我遇到了一个问题,我在java中使用2d数组进行循环,但我的指令已经在2个循环中,用于执行不同的操作。 通常情况下,应该是这样: public class stack { private int tab[][] = new int[26][26]; public static void main(String[] args){ stack fen = new stack(); } public stack() { this.tab[0][5] = 2;

我遇到了一个问题,我在java中使用2d数组进行循环,但我的指令已经在2个循环中,用于执行不同的操作。 通常情况下,应该是这样:

public class stack {
private int tab[][] = new int[26][26];


  public static void main(String[] args){
      stack fen = new stack();
  }

public stack() {
    this.tab[0][5] = 2;
    for(int x = 0;x<25;x++) {
        for(int y=0;y<25;y++) {
        System.out.print(this.tab[y][x] + "  ");
        }
        System.out.println();
    }   
}}
公共类堆栈{
私有整数选项卡[][]=新整数[26][26];
公共静态void main(字符串[]args){
stack fen=新堆栈();
}
公共堆栈(){
此.tab[0][5]=2;

对于(int x=0;x而言,问题在于您在同一点上更新
x1
y1
,而不是在右侧
循环中增加
x1
。 将
的两个
循环替换为:

for (int y = 0; y < 910; y += 35) {
    for (int x = 0; x < 910; x += 35) {
        // Placer(this.tab[5][25], x, y);
        // Placer(this.tab[x1][y1], x, y);
        System.out.print(this.tab[y1][x1] + "  ");
        x1++;
    }
    System.out.println();
    x1=0;
    y1++;
}
for(int y=0;y<910;y+=35){
对于(int x=0;x<910;x+=35){
//砂矿(本表[5][25],x,y);
//砂矿(此表[x1][y1],x,y);
System.out.print(此.tab[y1][x1]+“”);
x1++;
}
System.out.println();
x1=0;
y1++;
}

要添加到Dirks answer,可以在for循环中声明和更新多个变量:

for (int y = 0, y1 = 0; y < 910; y += 35, y1++) {
    for (int x = 0, x1 = 0; x < 910; x += 35, x1++) {
        // Placer(this.tab[5][25], x, y);
        // Placer(this.tab[x1][y1], x, y);
        System.out.print(this.tab[y1][x1] + "  ");
    }
    System.out.println();
}
for(int y=0,y1=0;y<910;y+=35,y1++){
对于(int x=0,x1=0;x<910;x+=35,x1++){
//砂矿(本表[5][25],x,y);
//砂矿(此表[x1][y1],x,y);
System.out.print(此.tab[y1][x1]+“”);
}
System.out.println();
}

我不知道,这是个不错的补充!
for (int y = 0, y1 = 0; y < 910; y += 35, y1++) {
    for (int x = 0, x1 = 0; x < 910; x += 35, x1++) {
        // Placer(this.tab[5][25], x, y);
        // Placer(this.tab[x1][y1], x, y);
        System.out.print(this.tab[y1][x1] + "  ");
    }
    System.out.println();
}