File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Customer Requirements for Developers this week in the Jobs Discussion 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

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

Alexandra Fard

Joined: Feb 28, 2013
Posts: 1

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

Steve Luke

Joined: Jan 28, 2003
Posts: 4181

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.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43410
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.
Consider Paul's rocket mass heater.
subject: "copy"(or create refrences) selected elements from one array to another
jQuery in Action, 3rd edition