programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# searching an array

Greenhorn
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?

Java Cowboy
Sheriff
Posts: 16079
88
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.

 I can't take it! You are too smart for me! Here is the tiny ad: The WEB SERVICES and JAX-RS Course https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS