java eclipse混合字符串和int数组

java eclipse混合字符串和int数组,java,arrays,string,object,int,Java,Arrays,String,Object,Int,在此订单上打印表格 由于我的英语和java不好,我尽可能多地编辑了这些代码上面的代码有几处错误: //First we need to set a spacing for each item, //else the table will look bad and not be in line: int spacing = 14; //Now loop through the array and store each item in `rowToPrint` //The for loop wil

在此订单上打印表格
由于我的英语和java不好,我尽可能多地编辑了这些代码

上面的代码有几处错误:

//First we need to set a spacing for each item,
//else the table will look bad and not be in line:
int spacing = 14;

//Now loop through the array and store each item in `rowToPrint`
//The for loop will repeat for each row
for (int row = 0; row < array2d.length; row++)
{
    //Create a string to store a whole row for printing:
    String rowToPrint = "";

    //The for loop will repeat for each column
    for (int column = 0; column < array2d[row].length; column++)
    {
        //get previous row items
        String previousItems = rowToPrint;

        //get next array item
        String newItem = array2d[row][column];

        //work out array item length
        int length = array2d[row][column].length();

        //work out padding for this item by doing (Spacing - array item length), and add blank spaces.
        //Example: 14(spacing) - 8 (item length) = 6 spaces of padding
        String padding = String.format("%" + (spacing - length) + "s", "");

        //now add add it all together
        rowToPrint = previousItems + newItem + padding;
    }

    //Now print current row in full with spacing/padding
    System.out.println(rowToPrint);
}
2D数组矩阵在对象上循环打印时,使用int作为索引

student name firstest secondtest schoolworks homeworks finaltest total grade 
    jack        15        10          8           7         35         67
公共类测试{
公共静态void main(字符串[]args)
{
Object[]array2d=新对象[3][7];
数组2d[0][0]=“ااااااب”;
array2d[0][1]=“1”;
array2d[0][2]=“1”;
数组2d[0][3]=“المشاكه”;
数组2d[0][4]=“الا㶎㶎㶎”;
数组2d[0][5]=“1575”和“1576”;
数组2d[0][6]=“المجوع”;
数组2d[1][0]=“عبداله”;
array2d[1][1]=新整数(15);
array2d[1][2]=新整数(10);
array2d[1][3]=新整数(7);
array2d[1][4]=新整数(8);
array2d[1][5]=新整数(35);
array2d[1][6]=新整数(75);
array2d[1][0]=“محمد”//不确定是否应该重新分配数组元素,尽管可以
array2d[1][1]=新整数(19);
array2d[1][2]=新整数(15);
array2d[1][3]=新整数(9);
array2d[1][4]=新整数(5);
array2d[1][5]=新整数(30);
array2d[1][6]=新整数(78);
for(int row=0;row
要打印出与您在文章中的表现类似的内容,需要经过一些思考,其中涉及到许多步骤。以下是一些让您开始学习的内容:

public class Test{
public static void main(String[] args)
{
    Object[][] array2d = new Object[3][7];

    array2d[0][0] = "اسم الطالب";
    array2d[0][1] = "اختبارالاول";
    array2d[0][2] = "اختبارالثاني";
    array2d[0][3] = "المشاركه";
    array2d[0][4] = "الواجبات";
    array2d[0][5] = "الاختبار النهائي";
    array2d[0][6] = "المجموع";

    array2d[1][0] = "عبدالله";
    array2d[1][1] = new Integer(15);
    array2d[1][2] = new Integer(10);
    array2d[1][3] = new Integer(7);
    array2d[1][4] = new Integer(8);
    array2d[1][5] = new Integer(35);
    array2d[1][6] = new Integer(75);

    array2d[1][0] = "محمد"; // Not sure if you should be reassigning the array elements, although you can
    array2d[1][1] = new Integer(19);
    array2d[1][2] = new Integer(15);
    array2d[1][3] = new Integer(9);
    array2d[1][4] = new Integer(5);
    array2d[1][5] = new Integer(30);
    array2d[1][6] = new Integer(78);

    for (int row = 0; row < array2d.length; row++)
    {

        for (int colums = 0; colums < array2d[row].length; colums++)
            System.out.println(array2d[row][colums]);
    }
}}

您正在设置
array2d[1][1]=新整数(15)
然后
array2d[1][1]=新整数(19)
也许你想做
array2d[1][2]=新整数(19)第二次?如果不这样做,如果您尝试打印空值,将得到NullPointerException。您需要编辑问题以进行修改。评论看起来很混乱。欢迎来到StackOverflow。但是,你的英语必须足以理解中的规则,并理解我们的答案。请不要在注释中添加代码,也不要添加与问题无关的文本,如“帮助”。
//First we need to set a spacing for each item,
//else the table will look bad and not be in line:
int spacing = 14;

//Now loop through the array and store each item in `rowToPrint`
//The for loop will repeat for each row
for (int row = 0; row < array2d.length; row++)
{
    //Create a string to store a whole row for printing:
    String rowToPrint = "";

    //The for loop will repeat for each column
    for (int column = 0; column < array2d[row].length; column++)
    {
        //get previous row items
        String previousItems = rowToPrint;

        //get next array item
        String newItem = array2d[row][column];

        //work out array item length
        int length = array2d[row][column].length();

        //work out padding for this item by doing (Spacing - array item length), and add blank spaces.
        //Example: 14(spacing) - 8 (item length) = 6 spaces of padding
        String padding = String.format("%" + (spacing - length) + "s", "");

        //now add add it all together
        rowToPrint = previousItems + newItem + padding;
    }

    //Now print current row in full with spacing/padding
    System.out.println(rowToPrint);
}
student name  firstest      secondtest    schoolworks   homeworks     finaltest     total grade   
jack          15            10            7             8             35            75            
john          19            15            9             5             30            78