This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""copy"(or create refrences) selected elements from one array to another" Watch ""copy"(or create refrences) selected elements from one array to another" New topic
Author

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

Alexandra Fard
Greenhorn

Joined: Feb 28, 2013
Posts: 1
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
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "copy"(or create refrences) selected elements from one array to another