Joey Deguzman :
I need to create a grid that a user can generate by adding the rows and columns ( r x c) but I need the grid to be from ascending to descending.
I have created a method that is able to create the grid:
static void createGrid(int n, int m){
int grid[][] = new int[n][m];
for(int i = grid.length - 1; i >= 0; i--) {
System.out.println();
for(int j = 0; j < grid.length; j++) {
grid[i][j] = i * n + j + 1;
System.out.print(grid[i][j] + "\t");
}
}}
the output right now is from a 3x3:
7 8 9
4 5 6
1 2 3
the expected output should be
1 2 3
4 5 6
7 8 9
nullPointer :
change your outer for loop from :
for(int i = grid.length - 1; i >= 0; i--) {
to :
for(int i = 0; i < grid.length ; i++) {
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325241&siteId=1