• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

searching an array

 
emlyn evanss
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic