简体   繁体   English

如何正确显示和0,0的2x2数组,就像在网格中一样?

[英]how to display properly and 2x2 array with 0,0 just like in grid?

how can i create an 2x2 array just like the one in the bottom. 我该如何创建一个2x2数组,就像底部的数组一样。 Take note that the coordinate 0,0 is at the bottom left. 请注意,坐标0,0在左下方。

(0,2) (1,2) (2,2)
(0,1) (1,1) (2,1) 
(0,0) (1,0) (2,0)

Currently 目前

im using something like this: 即时通讯使用这样的事情:

int[][] matrix = new int[width][height];
    for (int x = 0; x < matrix.length; x++) {
        for (int y = 0; y < matrix[x].length; y++) {
//println
    }}

but when i try to access the data the coordinates are as follows: 但是当我尝试访问数据时,坐标如下:

(0,0) (1,0) (2,0)
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)

your help is deeply appreciated. 非常感谢您的帮助。

You need to iterate over the inner array in reverse order first to achieve the desired ordering: 您需要首先以相反的顺序迭代内部数组以实现所需的顺序:

int[][] matrix = new int[width][height];
for (int y = height - 1; y >= 0; y--) {
    for (int x = 0; x < width; x++) {
        System.out.print(matrix[x][y] + " ");
    }
    System.out.println();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM