Java, loop through 2d array in any direction
问题 I'm trying to shift elements in an 2d array in any direction specified. By shift I mean, if left is pressed, each element of the array is moved as far to the left as it can. so this (0 indicated an empty space), 1 0 2 0 0 3 0 1 1 0 6 9 1 0 0 0 would become 1 2 0 0 3 1 0 0 1 6 9 0 1 0 0 0 This is sudo code of what I have for if 'up' is pressed; for col = 0 to SIZE for i = 0 to SIZE - 1 if array[i][col] == 0 for j = i to SIZE if array[j][col] != 0 array[i][col] = array[row][j] array[j][col] = 0