title: Move numbers in directions in multidimensional array java
body: <p>I am programming a 2048 clone (a simple one) and the method I am working on is sliding the numbers in the multidimensional array as far as posible in the specified direction. I have this code for sliding left but I can't figure out how to adapt it to slide up, down and right.</p>
  
  <pre><code>public void moveLeft(int[][] grid)
  {
      int [][] copy = grid;
      for(int x = 0; x &lt; copy.length; x++){
          int[] row = new int[4];
          for(int y = 0; y &lt; copy[x].length; y++){
  
              if (copy[x][y] != 0)
              {
                  int temp = 0;
                  while(row[temp] != 0) {
                      temp++;
                  }
                  row[temp] = copy[x][y];
              }
  
          }
          copy[x] = row;
      }
      grid = copy;
  }
  </code></pre>
  
  <p>Any ideas? Thanks a lot</p>