title: Column sort an array?
body: <p>I want to column-sort a multi-dimensional array. I have the code setup, but it's not displaying the right results...</p>
  
  <p>Example before sorting:</p>
  
  <p>6.0  4.0 2.0</p>
  
  <p>4.0  2.0  4.0</p>
  
  <p>1.0  3.0  1.0</p>
  
  <p>Example after sorting:</p>
  
  <p>1.0 2.0 1.0</p>
  
  <p>4.0 3.0 2.0</p>
  
  <p>6.0 4.0 4.0</p>
  
  <p>This is my code:  </p>
  
  <pre><code>  import java.util.Scanner;
  
      public class ColumnSorting
      {
     public static void main(String [] args)
     {
       run();
     }
     public static void run()
     {
        Scanner input = new Scanner(System.in);
        System.out.print("Please enter the values of your 3x3 matrix: ");
        double[][] matrix = new double[3][3];
        for (int i = 0; i &lt; matrix.length; i++)
        {
           for (int k = 0; k &lt; matrix[i].length; k++)
           {
              matrix[i][k] = input.nextDouble();
           }
        }
        printArrays(matrix);
  
      }
     public static void printArrays(double[][] matrix)
     {
     System.out.println("Before sorting: ");
  
         for (int i = 0; i &lt; matrix.length; i++)
        {
          for (int k = 0; k &lt;matrix[i].length; k++)
           {
              System.out.print(matrix[i][k] + " ");
           }
           System.out.println();
        }
      double[][] newMatrix = sortColumns(matrix);
       System.out.println();
      System.out.println("After sorting: ");
  
      for (int i = 0; i &lt; newMatrix.length; i++)
        {
           for (int j =0; j &lt; newMatrix[i].length; j++)
           {
              System.out.print(newMatrix[i][j] + " ");
           }
           System.out.println();
        }  
  
     }
     public static double[][] sortColumns(double[][] m)
     {
        double min;
        double temp;
        for (int i = 0; i &lt; 3; i++)
        {
           min = m[0][i];
           for (int k = 0; k &lt; m.length; k++)
           {
  
              if (min &gt; m[k][i])
              {
                 temp = min;
                 m[0][i] = m[k][i];
                 m[k][i] = temp;
              }
           }
        }
        return m;
  
     }
  }
  </code></pre>
  
  <p>This is what i'm getting:</p>
  
  <p>1.0 3.0 1.0 </p>
  
  <p>6.0 4.0 4.0</p>
  
  <p>6.0 4.0 2.0  </p>
  
  <p>Please tell me what i'm doing wrong!</p>
  
  <p>Thanks!</p>