为2d数组制作网格

时间:2016-04-12 04:13:26

标签: java arrays

我需要为一个二维数组创建一个网格用于hw赋值,并且不确定这是否是格式化它的正确方法。这是我的代码:

  public void showSeats() {

    System.out.print(" ");

    for (int i = 0; i < p[0].length; i++) {
        System.out.printf("|%10d|", i);
    }
    for (int i = 0; i < p.length; i++) {

        System.out.println();
        System.out.print(i);
        for (int j = 0; j < p[i].length; j++) {

            System.out.printf("|%10s|", p[i][j].getName());
        }
    }

    System.out.println();
}

基本上我需要使用printf和for循环的正确格式。如果有更简单的方法请告诉我们。输出应如下所示:

 output:

 |         0||         1|
0|Passenger1||Passenger2|
1|Passenger3||Passenger4|

错误:

Estimate of Problem Coverage (63%)
Problem coverage: 63%

For this assignment, the proportion of the problem that is covered by your solution is being assessed by running a suite of reference tests against your solution.

Test results indicate that your code still contains bugs. Your code appears to cover only 63% of the behavior required for this assignment.

Double check that you have carefully followed all initial conditions requested in the assignment in setting up your solution, and that you have also met all requirements for a complete solution in the final state of your program.

The following hint(s) may help you locate some ways in which your solution may be improved:

Test 4: 'remove' example output mismatch at line 9 Expected: | 0|| 1| Actual: | 0|| 1|

Test 2: 'seats' example output mismatch at line 6 Expected: | 0|| 1| Actual: | 0|| 1|

Test 3: 'add' example output mismatch at line 9 Expected: | 0|| 1| Actual: | 0|| 1|

0 个答案:

没有答案