title: Print data of Nodes with multiple children [Java]
body: <p>Hey to all Stackoverflowers!:D</p>
  
  <p><strong>This is my first question ever on stackoverflow, I appreciate any advice for my next questions!</strong></p>
  
  <p>I want to print out the data of all nodes in a tree data structure. I already have some code, but I get weird results. </p>
  
  <p>-Every node can have multiple children, those are stored in a List of nodes
  <br>
  -I always start with the root </p>
  
  <p>Here is my Code:</p>
  
  <pre><code>    public static void printTree(Knoten blatt){      
      Aufgabe1.Gewichte = Aufgabe1.Gewichte + blatt.Gewicht;
      System.out.println(blatt.Gewicht);
  
      for(int i=0;i&lt;blatt.children.size();i++) {
          blatt = blatt.children.get(i);
          printTree(blatt);
      } 
  }
  </code></pre>
  
  <p>But if I call this function my programm does not print out all nodes.
  I know this since I print the data while creating the nodes, I get this:</p>
  
  <pre><code>3.0
  27.0
  -6.0
  -7.0
  10.0
  -5.0
  -47.0
  -13.0
  -5.0
  </code></pre>
  
  <p>If I print it out with my recursive function, I get this:</p>
  
  <pre><code>3.0
  27.0
  -6.0
  -7.0
  10.0
  -5.0
  -47.0
  -13.0
  </code></pre>
  
  <p>-47 is the parent, with the children -13 and -5, -5 just doesnt want to get printed tho.</p>
  
  <p>If I print it out manually, like root.children.children...get(i) whatever, I can access both kids, with the right data... 
  I seriously have no clue where my fault is in my code, would be great if someone can help me...
  I am sure im just kinda blind :D</p>
  
  <p>I also tried some other trees, sometimes this error wont show up, sometimes it will...</p>
  
  <p>The Tree-Structure looks like this:
  <a href="https://i.stack.imgur.com/NnOL8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NnOL8.png" alt="enter image description here"></a></p>
  
  <p>Thanks for your help, I hope my question is understandable</p>