title: Check if a binary tree is full in Java?
body: <p>I am trying to write a method that will return true if a binary tree is full (each node has 2 child nodes or none) and false otherwise. This is working some of the time but not all. Any suggestions about where I am going wrong?</p>
  
  <pre><code>public static void testNum4()
      {
          System.out.println("How many nodes do you want in your tree?");
          int num=sc.nextInt();
          //TreeNode&lt;Integer&gt; root = TreeUtil.createBalancedNumberTree(num);  Use to test for a balanced tree
          TreeNode&lt;Integer&gt; root = TreeUtil.createIntegerTree(num);
          TreeUtil.displayTreeInWindow(root);
          System.out.println(isFull(root));
          TreeUtil.displayTreeInWindow (root);
      }
  
      public static boolean isFull(TreeNode&lt;Integer&gt;  root) {
      // pre: root of tree, 0 or more nodes
      // post: returns true if the input tree is a full tree; false otherwise
  
          if (root!=null) {
              if ((root.getLeft() != null &amp;&amp; root.getRight() != null) || (root.getRight() == null &amp;&amp; root.getLeft() == null))
              {
                  return true;
              }
              else if (root.getLeft()!=null)
              {
                  isFull(root.getLeft());
              }
              else if (root.getRight()!=null)
              {
                  isFull(root.getRight());
              }
              else 
                  return false;
  
          }
              return false;
      }
  </code></pre>