• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"copy"(or create refrences) selected elements from one array to another

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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).


/Alexandra
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
You should always use the code button; I have been back to your post with the code button, and you can see how much better it looks .  Note: coloured text cannot be used in code.
reply
    Bookmark Topic Watch Topic
  • New Topic