2D Java数组值与我的意图不相关

2D Java数组值与我的意图不相关,java,arrays,Java,Arrays,这是我的代码: import java.util.Scanner; import java.util.Arrays; public class Fire { public static Integer seed; public static Integer width; public static Integer height; public static void main(String[] args) { if (args.length

这是我的代码:

import java.util.Scanner;
import java.util.Arrays;

public class Fire {

    public static Integer seed;
    public static Integer width;
    public static Integer height;

    public static void main(String[] args) {
        if (args.length != 3) {
            System.out.println("Usage: java Firebot <seed> <width> <height>");
            return;
        }
        try {
            width = Integer.parseInt(args[1]);
            height = Integer.parseInt(args[2]);
        } catch (Exception e) {
            System.out.println("Usage: java Firebot <seed> <width> <height>");
            return;
        }
        Scanner keyboard = new Scanner (System.in);
        Integer day = 1;
        String wind = "none";
        double damage = 0.00;
        Integer pollution = 0;

        Integer seed = Integer.parseInt(args[0]);
        Integer width = Integer.parseInt(args[1]);
        Integer height = Integer.parseInt(args[2]);

        int [][] SimulationArray = new int[width][height];
        for (int i=0; i<width; i++) {
            for (int j=0; j<height; j++) {
                Integer DoubleHeight = (int) Math.round(Math.random() * 10);
                if (DoubleHeight == 10) {
                    SimulationArray[i][j] = 0;
                }
                else if (DoubleHeight > 2) {
                    SimulationArray[i][j] = DoubleHeight;
                }
                else {
                    SimulationArray[i][j] = 0;
                }
            }
        }

        for (int i=0; i<width; i++) {
                for (int j=0; j<height; j++) {
                    if (SimulationArray[i][j] == 0) {
                        System.out.print("  ");
                        }
                    else {
                        System.out.print(Arrays.toString(SimulationArray[i]));
                        System.out.print("  ");
                    }
                }
            System.out.println();
            }
        System.out.print("\n");

    }
}
实际上,我想要打印的是这样的东西

[user@sahara ~]$ java Fire 4 5 4

4 5 2 3 4
2 3 4 4 5
4 5 2 3 4
2 3 4 4 5
3 4 7 8 2
没有[]和单个整数。我觉得这就是我的代码应该做的(如果整数是0或10,则不包括空格应该打印的位)。 有谁能告诉我为什么要这样打印[0,8,8,6]

我试过了

System.out.print(Arrays.toString(SimulationArray[i][j]));
使用上面的方法我会得到错误。我怀疑我是在打印子数组,而不是打印单个值,但我不明白为什么或如何解决这个问题


谢谢你的帮助。谢谢。

使用嵌套for循环打印二维数组

for(int i = 0; i<iLength; i++){
for(int i = 0; i<iLength; i++){
System.out.print(SimulationArray[i][j] +" ");
}
System.out.println("");
}

对于(int i=0;i要打印二维数组,可以对每个循环使用嵌套,如下所示:

for (int[] x : SimulationArray) {
    for (int y : x) {
        System.out.print(y + " ");
    }
    System.out.println();
}

代码的相关部分应该在问题本身中,而不是在一个容易消失的pastebin链接中。
for (int[] x : SimulationArray) {
    for (int y : x) {
        System.out.print(y + " ");
    }
    System.out.println();
}