Java 为什么我的第二个数组没有完全打印出来?
我正在尝试在列和行中创建以下数字的表示形式 为什么我的第二个数组没有完全打印出来 此外,数字并不是以行和列的方式打印的。为什么会这样Java 为什么我的第二个数组没有完全打印出来?,java,arrays,eclipse,for-loop,Java,Arrays,Eclipse,For Loop,我正在尝试在列和行中创建以下数字的表示形式 为什么我的第二个数组没有完全打印出来 此外,数字并不是以行和列的方式打印的。为什么会这样 public class MultidimensionalArrays { public static void main(String[] args) { //initializes rows and columns //first box = row, second box = column int firstarray[][]
public class MultidimensionalArrays
{
public static void main(String[] args)
{
//initializes rows and columns
//first box = row, second box = column
int firstarray[][] = {{3, 4, 5, 6,} , {8, 9}};
//System.out.println(firstarray[0][1]) = 9;
//initializes another rows and columns
int secondarray[][] = {{11, 12, 13} , {88} , {100, 200, 300} , {33, 35, 37}};
//displays the 1st array
System.out.println("this is the 1st array: ");
display(firstarray);
System.out.println();
//displays the 2nd array
System.out.println("this is the 2nd array: ");
display(secondarray);
}
//makes a method to display out the arrays
public static void display(int x[][])
{
//makes a for-loop that prints out the row
for(int row = 0; row < x.length; row++)
{
//makes a for-loop that prints out the column
for(int column = 0; column < x.length; column++)
{
//sysouts the rows & columns
System.out.print(x[row][column] + "\t");
}
}
}
}
数组不是矩阵,因此列长度不等于行长度。事实上,不同的行具有不同的列数,因此必须使用每行的单独长度 尝试:
for(int row=0;row
您的数组不是矩阵,因此列长度不等于行长度。事实上,不同的行具有不同的列数,因此必须使用每行的单独长度
尝试:
for(int row=0;row
您正在使用行数打印列。这些显然与您的测试用例不匹配。这样修改
//makes a for-loop that prints out the row
for(int row = 0; row < x.length; row++)
{
//makes a for-loop that prints out the column
for(int column = 0; column < x[row].length; column++)
{
//sysouts the rows & columns
System.out.print(x[row][column] + "\t");
}
System.out.println();
}
//生成一个for循环,用于打印该行
对于(int row=0;row
您可能还应该在每行之后打印一行。我为此添加了代码。您正在使用行数打印列。这些显然与您的测试用例不匹配。这样修改
//makes a for-loop that prints out the row
for(int row = 0; row < x.length; row++)
{
//makes a for-loop that prints out the column
for(int column = 0; column < x[row].length; column++)
{
//sysouts the rows & columns
System.out.print(x[row][column] + "\t");
}
System.out.println();
}
//生成一个for循环,用于打印该行
对于(int row=0;row
您可能还应该在每行之后打印一行。我为此添加了代码
//makes a for-loop that prints out the row
for(int row = 0; row < x.length; row++)
{
//makes a for-loop that prints out the column
for(int column = 0; column < x[row].length; column++)
{
//sysouts the rows & columns
System.out.print(x[row][column] + "\t");
}
System.out.println();
}