aspose file tools*
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
Author

searching an array

emlyn evanss
Greenhorn

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?

ie

grid[0][0]={1,2,3,4,5,6,7,8,9}
grid[0][1]={1,0,2,0,0,0,0,0,0}

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: 14105
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: searching an array