title: Store multiple 2D matrices in an array
body: <p>I'm trying to store multiple matrices into an array (each matrix has the same dimension), and I think my logic is correct, but the code isn't running correctly. My inputs from the text file look like this (for example):</p>
  
  <pre><code>0 0 0 0 0 
   0 0 0 0 0 
  0 0 0 0 0
  
  0000000000
  00      00
  0000000000
  
  000 00 000
  00 000 00 
  000 00 000 
  </code></pre>
  
  <p>So in the example, each ' ' counts as a character which I convert to a -1, and each new lines is a new matrix. I've already found the number of rows and columns, and I'm told the number of pairs I will see in the text file. So I want to make an array like this </p>
  
  <pre><code>pairs[number of pairs][rows][columns]. 
  </code></pre>
  
  <p>So in this example, it would be pairs[3][3][10] so 3 samples each with a 3 x 10 matrix. My code is:</p>
  
  <pre><code>int lines = 0;
  BufferedReader brr = new BufferedReader(new FileReader(inFile));
          //now read and store in 2D matrix
          int[][][] samples = new int[pairs][rows][cols];
          while((lines = brr.readLine()) != null) {
              if (line &gt; 2) { // to skip first 3 lines of text file
                  for (int i = 0; i &lt; pairs; i++) {
                      for (int j = 0; j &lt; rows; j++) {
                          for (int k = 0; k &lt; lines.length(); k++) {
                              //Cycle through each character in line
                              if (lines.charAt(k) == 'O' || lines.charAt(k) == '0') {
                                  samples[i][j][k] = 1; //store in the matrix as a 1
                              }
                              else if (lines.charAt(k) == ' ') {
  
                                  samples[i][j][k] = -1;
                                  //store spaces as -1
                              }
  
                          }
                      }
                  }
              }
              line++;
          }
          br.close();
  </code></pre>
  
  <p>Sorry, I meant to write my output, but right now it's assigning the variables, but it continues to repeat. What I mean is that once it finishes the 3rd input, the for loops just repeat again. In other words, once i = 2 (in this example), and j = 2, k = 2, it then repeats and everything goes through again from the beginning for some reason. </p>