title: swapping values in multi-dimensional array
body: <p>im currently working on a problem where i need to swap the values in the multi-dimensional array based on a condition. example of the inputs:</p>
  
  <pre><code>2 3
  
  4 5
  
  5 2
  
  6 25
  </code></pre>
  
  <p>the above elements are in a array of 4 rows and 2 columns (columns = 2 is fixed).
  If the value is column is greater than value in the row, then nothing has to be changed, else the values should be interchanged.</p>
  
  <p>please find my code below:</p>
  
  <pre><code>int c = 2;
  int temp1, temp2;
  Scanner in = new Scanner(System.in);
  System.out.println("Enter 'n': ");
  n = in.nextInt();
  
  int[][] arr = new int[n][c];
  
  if (n &lt;= 15) {
      for (int i = 0; i &lt; n; i++) {
          for (int j = 0; j &lt; c; j++) {
              System.out.println("Enter values into md-array: ");
              arr[i][j] = in.nextInt();
          }
      }
      for (int i = 0; i &lt; n; i++) {
          for (int j = 0; j &lt; c; j++) {
              if (arr[i][j] &lt; arr[i][j + 1]) {
                  System.out.println(arr[i][j]);
              } else {
                  temp2 = i; //swapping
                  i = j;
                  j = temp2;
  
                  temp1 = j;
                  j = i;
                  i = temp1;
  
                  System.out.println(arr[i][j]);
              }
          }
      }
  }
  </code></pre>
  
  <p>When I'm trying out with the above code, I could write the elements into the array but I'm not able to perform the swap operation nor the initial compare operation. I'm also facing the <code>IndexOutOfBoundsException</code>. I'm not able to rectify this.</p>