如何在每次迭代时更改数组?

时间:2017-11-05 08:15:09

标签: java arrays

我评论了这个问题!我希望它首先说宝马,然后是现代,最后是道奇。

    String[] [] cars = new String[3] [2];
    cars [0] [0] = "BMW";
    cars [0] [1] = "i7!";
    cars [1] [0] = "Hyundai";
    cars [1] [1] = "Tuscon!";
    cars [2] [0] = "Dodge";
    cars [2] [1] = "Challenger!";

    for (int i = 0; i < cars.length; i++) {
        StringBuilder sa = new StringBuilder();
        for (int j = 0; j < cars[i].length; j++) {
            if ( j == 0) {
                // what can I do to make the final statement (the name of manufacturer change for each time it is printed out, instead of i.e BMW for all of em
                sa.append ("The manufacturer " + cars1 [0] [0] ); sa.append (" has just published a video of ");
            } else {
                sa.append(" the model ");
            }
            sa.append(cars [i] [j]);
        }

        System.out.println(sa);
    }
}

}

1 个答案:

答案 0 :(得分:0)

您只需要更改:

sa.append ("The manufacturer " + cars [0] [0] );

进入:

sa.append ("The manufacturer " + cars [i] [j] );

相关问题