title: Java Two Dimensional Array Boolean
body: <p>My homework is to create a (not so) simple recreation of Conway's Game of Life. Exact Instructions:</p>
  
  <blockquote>
    <ol>
    <li>Prompt the user to enter a list of (i,j) pairs (both non-negative integers)                (stop when a negative integer is read for either i
    or j)     </li>
    <li>Prompt the user to enter the number of time steps  </li>
    <li>Initialize the grid based on the (i,j) pairs entered by the user   </li>
    <li>Display the initial state of the grid      (call the <code>displayGrid()</code> method)   </li>
    <li>For each time step, update the grid according to Conway’s rules (call the <code>updateGrid()</code> method) and display the grid (call the
    <code>displayGrid()</code> method)</li>
    </ol>
  </blockquote>
  
  <p>My programs output has now changed:</p>
  
  <pre><code>Please enter list of (i, j) pairs for populated cells(negative i or j to quit):
  6 4 6 5 6 6 6 7 6 8
  -1 -1
  Enter number of time steps:
  2
  Initial Grid:
  
  
  
  
  
  
     ######
  
  
  
  Time step 1
  
  
  
  
  
  
  
  
  
  
  Time step 2
  </code></pre>
  
  <p>My new question is what is making my code "kill" everything? Why isn't there any "true"s? </p>
  
  <p>Here's my code:</p>
  
  <pre><code>java.util.Scanner;
  
    class P8{
      public static void main(String[] args){
         Scanner in = new Scanner(System.in);
         boolean[][] multi = new boolean[10][10];
         int i, j, N, x, y, h;
  
         for(x=1; x&lt;multi.length; x++){
            for(y=1; y&lt;multi.length; y++){
               multi[x][y] = false;
            }
         }
         System.out.println("Please enter list of (i, j) pairs for populated cells(negative i or j to quit):");
  
         while(true){
            i = in.nextInt();
            j = in.nextInt();
            if(i &lt;= 0 || j &lt;= 0){
               break;}
  
            multi[i][j] = true;
            }
  
         System.out.println("Enter number of time steps:");
         N = in.nextInt();
         System.out.println("Initial Grid: \n");
         displayGrid(multi);
         for(i = 1; i&lt;N+1; i++){
            System.out.printf("Time step %d\n", i);
            updateGrid(multi);
            displayGrid(multi);
            System.out.println("\n");
         }
   }
  
         /******************************************
         void updateGrid(boolean mat[][]); updates
         the 2 dimensional array using Conway's
         standard rules. Does this by calling
         "neighbors" function
         ******************************************/
         public static void updateGrid(boolean mat[][]){
            boolean[][] temp = new boolean[mat.length][mat.length];
            int i, j, row, col, n=0;
  
            for(row = 0; row &lt; mat.length; row++){
               for(col = 0; col &lt; mat.length; col++){
               neighbors(mat, row, col);
  
               if(n&gt;=4 || n&lt;=1)
                  mat[row][col] = false;
               else
                  mat[row][col] = true;
  
               }
            }
         }
  
         /******************************************
          void neighbors(boolean mat[][]int row, int col) 
          checks how many "neighbors" are around a given point
         ******************************************/
          public static int neighbors(boolean mat[][], int row, int col){
             int N =0;
             if((row-1 &gt;= 0)&amp;&amp;(col-1 &gt;= 0))
                N = mat[row-1][col-1] ? N + 1 : N;
  
             if((row &gt;=0)&amp;&amp;(col-1 &gt;= 0))
                N = mat[row][col-1] ? N+1 : N;
  
             if((row+1 &lt; mat.length)&amp;&amp;(col-1 &gt;= 0))
                N = mat[row+1][col-1] ? N+1 : N;
  
             if((row+1 &lt; mat.length)&amp;&amp;(col &lt; mat[0].length))
                N = mat[row+1][col] ? N+1 : N;
  
             if((row+1 &lt; mat.length)&amp;&amp;(col+1 &lt; mat[0].length))
                N = mat[row+1][col+1] ? N+1 : N;
  
             if((row &lt; mat.length)&amp;&amp;(col+1 &lt; mat[0].length))
                N = mat[row][col+1] ? N+1 : N;
  
             if((row-1 &gt;= 0)&amp;&amp;(col+1 &lt; mat[0].length))
                N = mat[row-1][col+1] ? N+1 : N;
  
             if((row-1 &gt;= 0)&amp;&amp;(col &lt; mat[0].length))
                N = mat[row-1][col] ? N+1 : N;
  
              return N;
         }
  
         /******************************************
          void displayGrid(int mat[][]) prints out
          a two dimensional array
         ******************************************/
         public static void displayGrid(boolean mat[][]){
            int x, y;
            for(x=1; x&lt;mat.length; x++){
               for(y = 1; y&lt;mat.length; y++){
                  if(mat[x][y])
                     System.out.printf("#");
                  else
                     System.out.printf(" ");
               }
               System.out.println();
            }
  
         }
    }
  </code></pre>
  
  <p>`</p>