I have a problem with my java class. The red marked code gets wrong. If I type in 4 children (2 above 4 and 2 younger than 4) the system.out.println write 4 older than 4. Hope someone knows what I mean and can explain for me what I'm doing wrong. I have not the code for the Child class in this message just the main class (the problem class).
I am not understanding the problem. You create an array of length 4, then print its length and get 4. That should be the expected case. The only problem with the lines in red and how they perform is the string text. You haven't counted how many children are above or under 4 yet, so you can't print that amount out. What they text should be is 'The number of children that might possibly be under 4.'
What you need to do is StopCoding (<- link) and use a pencil and paper to figure out how you should figure out the count of children above four, and the count of children under four. Visualize what you would do if the kids were in a line and you were able to speak to them just one at a time. How would you solve problem then? Right out the steps in your native tonque (not code) then make each step shorter, more precise, and probably the number of steps more. Once you are sure you could hand your instructions to a ten year old and expect him to be able to follow them and come to the correct conclusion, then you can start coding.