簡體   English   中英

如何正確顯示和0,0的2x2數組,就像在網格中一樣?

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

我該如何創建一個2x2數組,就像底部的數組一樣。 請注意,坐標0,0在左下方。

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

目前

即時通訊使用這樣的事情:

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

但是當我嘗試訪問數據時,坐標如下:

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

非常感謝您的幫助。

您需要首先以相反的順序迭代內部數組以實現所需的順序:

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