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 searching an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "searching an array" Watch "searching an array" New topic

searching an array

emlyn evanss

Joined: Apr 18, 2006
Posts: 1
hey guys, i'm a tad stuck, can anyone tell me how i can search through an array: grid[81][9] and find the which of the 81 sets of nine has the least data entries?



grid[0][1] obviously has the least entries, but how can i perform a search through the 81 sets?

Thankyou in advance
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15081

What did you try yourself so far and where exactly do you get stuck?

You don't say what you mean by "least data entries", but your example suggests that if an array element contains nothing but zeroes from a certain point on, the number of numbers before the zeroes determine the number of data entries.

You'd have to make a nested for-loop to do this - one loop that goes from 0 to 80, and a nested loop that looks at each of the series from 0 to 8. In the nested loop, you check how many data entries there are in that series. Outside the loop you maintain a variable that remembers where you've found the series with the least data entries upto that point.

Show us your code that you are stuck with, and we can give you some more specific hints.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: searching an array
It's not a secret anymore!