title: Method to rotate the specified row of a 4x4 array initialised with integers 0-15?
body: <p>Basically I have a 2D puzzle which is represented as a 4x4 integer array. The Array is initialised with integers 0..15 I have to Implement the method:</p>
  
  <pre><code>public static void play(int[][] puzzle)
  </code></pre>
  
  <p>method should take as its argument a 4x4 integer array that represents the puzzle after it has been scrambled. The method should be implemented using a loop that repeatedly:
  1.Prints the current state of the puzzle
  2.Asks the player to enter a rotation command
  3.Performs the rotation requested by the player
  The loop should terminate once the puzzle is back in its original unscrambled state which means it has to be back to the original Puzzle in order of the numbers 0 to 15.</p>
  
  <p>The program should display a congratulation message when this happens.</p>
  
  <p>The program should include user input validation.</p>
  
  <p>Whenever the user input is invalid, the program should print the warning Invalid input!
  User input is valid if it is in the form of one of the two commands row or column rotation.</p>
  
  <p>The template of the Puzzle is :</p>
  
  <pre><code>public class Puzzle {
  
      public static final int N = 4;
      public static final int NUMBER_OF_ROTATIONS = 5;
  
      public static void main(String[] args) {
          int[][] puzzle = new int[N][N];
          reset(puzzle);
          test(puzzle);
          reset(puzzle);
          scramble(puzzle);
          System.out.println("### Testing puzzle game play\n");
          play(puzzle);
      }
  
      public static void print(int[][] puzzle) {
          for (int[] row : puzzle) {
              for (int elem : row) {
                  System.out.printf("%4d", elem);
              }
              System.out.println();
          }
          System.out.println();
      }
  
      public static void test(int[][] puzzle) {
          System.out.println("### Testing reset method\n");
          print(puzzle);
          System.out.println("### Testing rotate methods\n");
          print(puzzle);
          for (int i = 0; i &lt; N; i++) {
              System.out.println("### rotateColumn(" + i + ")\n");
              rotateColumn(puzzle, i);
              print(puzzle);
              System.out.println("### rotateRow(" + i + ")\n");
              rotateRow(puzzle, i);
              print(puzzle);
          }
          reset(puzzle); 
          System.out.println("### Testing random rotations\n");
          print(puzzle); 
          for (int i = 0; i &lt; 5; i++){
              randomRotation(puzzle);
              print(puzzle); 
          }
      }
  
      public static void reset(int[][] puzzle) {
          for (int i = 0; i &lt; N; i++) {
              for (int j = 0; j &lt; N; j++)
                  puzzle[i][j] = i * N + j;
          }
      }
  
      public static void scramble(int[][] puzzle) {
          for (int i = 0; i &lt; NUMBER_OF_ROTATIONS; i++) {
              randomRotation(puzzle);
          }
      }
  
  
  
  
      public static void rotateRow(int[][] arr, int row) {
          for (int i= arr.length-1; i&gt;0; i--) {
              int r= (int) (Math.random() * (i+1)); int[] c = arr[i];
              arr [i] = arr[r];
              arr[r] = c;
          }
  
  
      }
  
  
      // TODO: Implement method as specified in assignment brief 
  
      public static void rotateColumn(int[][] arr, int column) {
      }
  
  
      // TODO: Implement method as specified in assignment brief 
  
      public static void randomRotation(int[][] puzzle) {
      }
  
      // TODO: Implement method as specified in assignment brief 
  
      static void play(int[][] puzzle) {
      }
  
  }
  </code></pre>
  
  <p>As you can see, I have tried to implement the rotating the row method but after I run it, the whole array gets changed instead of a specified row. Can someone please show me what I am doing wrong? Thank you :).</p>