How could I read Java Console Output into a 2d n*m double matrix/array
<p>here is code:</p>

<pre><code>import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ReadContents {
    public static void main(String[] args) throws IOException {
        File file = new File("file1.txt");
        List&lt;float[]&gt; list = new ArrayList&lt;float[]&gt;();
        Scanner scanner = new Scanner(file).useDelimiter("\n");



        while (scanner.hasNext()) {     
            String[] values = scanner.next().trim().split(" "); 
             float[] floats = new float[values.length];
             for (int i = 0; i &lt; values.length; i++) {
                 floats[i] = Float.parseFloat(values[i]);
                 }
                 list.add(floats);
                 } 
                 float[][] values = new float[list.size()][];
                 for (int i = 0; i &lt; list.size(); i++) {
                     values[i] = list.get(i);
                     for (int j = 0; j &lt; values[i].length; j++) {
                         System.out.print(values[i][j] + " ");

                         }
                         System.out.println();
                 }


                int row =values.length;
                 int col=values[0].length;

                 System.out.println(row);
                 System.out.println(col);

    //******************************************************************************************************************
                  System.out.println();
                   double sum;
                   double avg=0;

               for (int p = 0; p &lt; col; p++){
                   sum=0;
                   for (int k = 0; k &lt; row; k++){ 
                     sum = sum + values[k][p]; 
                     //avg=((double)sum / row);

                   }
                    avg=((double)sum / row);
                   System.out.print("average"+p+"=");
                  System.out.printf("%5.2f\n", avg);
               }
</code></pre>

<p>it gives output as file content in 2d matrix and also print averages of each column of "values[][]" matrix on console screen.now i want to print the matrix containing all averages calculated previously into single 2d n*m array.
pls guide me.</p>
