title: Writing a method that print binary tree and each node level number
body: <p>I need to write a method that prints a binary tree by using recursion. It must be that the signature of the method will be</p>
  
  <pre><code>public static void level(Node n)
  </code></pre>
  
  <p>so the method can get only the Node n and should not return anything, just print on screen.</p>
  
  <p>My problem is: I need that each level on the tree will print with his own level number,
  and i dont know how to do this cause if i put a counting integer it zero every time the recursion start.</p>
  
  <p>this is what i tried:</p>
  
  <pre><code>public static void level(Node n)
  {
      if (n.getLeftSon() == null &amp;&amp; n.getRightSon() == null)
          System.out.println(n.getNumber());
      else
      {
          System.out.println(n.getNumber()); 
          if (n.getLeftSon() != null)
              level(n.getLeftSon());
          if (n.getRightSon() != null)
              level(n.getRightSon()); 
      }
  
  }
  </code></pre>
  
  <p>it works printing the tree but without the levels number for each Node.</p>
  
  <p>OK so after help here in the forum i wrote this method like that:</p>
  
  <pre><code>public static void level(Node n)
  {
      levelAndNumbers(n,0);
  }
  
  private static void levelAndNumbers(Node n, int i)
  {
      if (n.getLeftSon() == null &amp;&amp; n.getRightSon() == null)
          System.out.println(n.getNumber()+"=&gt;"+i);
      else
      {
          System.out.println(n.getNumber()+"=&gt;"+i); 
          if (n.getLeftSon() != null)
              levelAndNumbers(n.getLeftSon(), i+1);
          if (n.getRightSon() != null)
              levelAndNumbers(n.getRightSon(), i+1); 
      }
  
  }
  </code></pre>
  
  <p><strong>and its working great!</strong></p>
  
  <p><strong>so from what i understand there is no way to do this only in the public method? i have to add another private method that get also a counting number...???</strong></p>