Java 使用多维数组制作垂直表

Java 使用多维数组制作垂直表,java,multidimensional-array,Java,Multidimensional Array,我已经使用多维数据库创建了一个表,但是当我运行它时,表似乎一直在水平运行,当它运行时,如何使它垂直排列 public static void main(String args[]){ int firstarray[][]={{1,2,3,4,5} ,{6,7,8,9,10}}; int secondarray[][]={{30,31,32,33,} ,{43},{4,5,6}};

我已经使用多维数据库创建了一个表,但是当我运行它时,表似乎一直在水平运行,当它运行时,如何使它垂直排列

public static void main(String args[]){
    int firstarray[][]={{1,2,3,4,5}
                        ,{6,7,8,9,10}};
    int secondarray[][]={{30,31,32,33,}
                        ,{43},{4,5,6}};

    System.out.println("This is the first array");
    display(firstarray);

    System.out.println("This is the second array");
    display(secondarray);
}
public static void display (int x[][]){
    for(int row=0;row<x.length;row++){
        for(int column=0;column<x[row].length;column++){
            System.out.print(x[row][column]+"\t");
        }
    }   
  }
}
publicstaticvoidmain(字符串参数[]){
int firstarray[][]={{1,2,3,4,5}
,{6,7,8,9,10}};
int secondarray[][]={{30,31,32,33,}
,{43},{4,5,6}};
System.out.println(“这是第一个数组”);
显示(第一阵列);
System.out.println(“这是第二个数组”);
显示器(第二阵列);
}
公共静态无效显示(int x[]{

对于(int row=0;row在内部循环之后打断每一行):

for (int row=0; row<x.length; row++) {
   for (int column=0; column<x[row].length; column++) {
      System.out.print(x[row][column]+"\t");
   }
   System.out.println(); // Break current line
}

用于(int row=0;rowinternal Loop为您打印出每一行的每一列,因此在每一行的末尾,您必须使用
System.out.println
转到与外循环相关的下一行。在更好的场景中,如果您想要有新行,在读取构成下一行的新列之前,您必须使用System.out.println`

希望此示例能帮助您更好地学习

代码:

       int a[][] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}};

        for (int i = 0; i < a.length; i++) {
            System.out.print("---> It is going to read colmuns in order to make a line");
            for (int j = 0; j < a[0].length; j++) {
                System.out.print(a[i][j]+" ");
            }
            System.out.println("-->It is going to make a new next line");
        }
---> It is going to read colmuns in order to make a line 1 2 3 4 5 -->It is going to make a new next line
---> It is going to read colmuns in order to make a line 6 7 8 9 10 -->It is going to make a new next line