title: Find all Non-Prime Paths in a triangle
body: <p>I'm trying to find routes that do not contain prime numbers in a triangle of integers leading from top to bottom.</p>
  <p>What is wrong with my code?</p>
  <p>For example (<code>int[][] input = {{1}, {8, 4}, {2, 6, 9}, {8, 5, 9, 3}}</code>),</p>
  <pre><code>   1    
    8 4
   2 6 9
  8 5 9 3
  </code></pre>
  <p>This triangle has three paths that meet these criteria:</p>
  <pre><code>1 - 8 - 6 - 9  
  1 - 4 - 6 - 9  
  1 - 4 - 9 - 9
  </code></pre>
  <p>How can I achieve this?</p>
  <p><em>My code:</em></p>
  <pre><code>private static void findPaths(int x, int y, int input[][])
  {
     if(x &lt; input.length - 1)
     {
       if(!isPrime(input[x + 1][y]) &amp; !isPrime(input[x + 1][y + 1]))
       {
           System.out.println(input[x + 1][y]);
           findPaths(x + 1, y, input);
              
           System.out.println(input[x + 1][y + 1]);
           findPaths(x + 1, y + 1, input);
       }
       else if(!isPrime(input[x + 1][y]))
       {
           System.out.println(input[x + 1][y]);
           findPaths(x + 1, y, input);
       }
       else if(!isPrime(input[x + 1][y + 1]))
       {
           System.out.println(input[x + 1][y + 1]);
           findPaths(x + 1, y + 1, input);
       }
     }
  }
  
  public static boolean isPrime(int num)
  {
    if (num &lt;= 1) {return false;}
  
    for (int i = 2; i * i &lt;= num; i++)
    {
       if ((num % i) == 0) {return false;}
    }
    return true;
  }
  </code></pre>
  <p>Results for <code>findPaths(0, 0, input)</code> (array <code>input</code> initialized as shown above):</p>
  <pre><code>8
  6
  9
  4
  6
  9
  9
  9
  </code></pre>