Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Problem  RSS feed

 
Ben Duffield
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!
I need to create two methods numbersInRange and nearestToTarget. The first method numbersInRange, which I have completed, just returns an integer giving the number of elements in the array whose value is greater than the parameter 60 and less than the parameter 80.
The second method is supposed to return the value of the integer in array closest to the target, which is 93 in this case. If there is more than one such integer in the array, the first such element in array needs to be returned.
Here is the whole code, note that I have completed the first method already.
Please help me in comleting the second method!

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's one way
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future, could we please focus efforts on helping someone to learn to figure out the solutions - not on giving them the solutions?
Thank you.
[ April 18, 2004: Message edited by: Dirk Schreckmann ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!