how can i create an 2x2 array just like the one in the bottom. Take note that the coordinate 0,0 is at the bottom left.
(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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.