BigestCountries 类有一个代码。
它由2个数组组成:
private String[][] biggestCountries; - holds country name and the continent, e.g. biggestCountries[CHINA][COUNTRY_NAME] = "China"; biggestCountries[CHINA][COUNTRY_CONTINENT] = "Asia";
private int[][] countryData; - holds populations and year founded, e.g. countryData[CHINA][COUNTRY_POPULATION] = 1433783686; countryData[CHINA][COUNTRY_AGE_FOUNDED] = 1949;
public String[] getCountriesFoundedBetween(int min, int max){
int countriesMatched;
countriesMatched = 0;
String[] countriesFoundedBetween;
if(biggestCountries == null || biggestCountries.length == 0){
return null;
}
for(int i = 0; i < biggestCountries.length; i++){
if(countryData[i][COUNTRY_AGE_FOUNDED] >= min && countryData[i][COUNTRY_AGE_FOUNDED] <= max){
System.out.println(String.format("%d %s", countryData[i][COUNTRY_AGE_FOUNDED], biggestCountries[i][COUNTRY_NAME]));
countriesMatched++;
}
}
if(countriesMatched > 0){
countriesFoundedBetween = new String[countriesMatched];
} else {
return null;
}
for(int i = 0; i < biggestCountries.length; i++) { // outer loop for countries array length of NUMBER_OF_COUNTRIES
String countryMatched = null;
System.out.println("biggestCountries[i] " + biggestCountries[i][COUNTRY_NAME]);
if(countryData[i][COUNTRY_AGE_FOUNDED] >= min && countryData[i][COUNTRY_AGE_FOUNDED] <= max){
for(int j = 0; j < countriesFoundedBetween.length; j++){ // how to escape inner loop?
countryMatched = biggestCountries[i][COUNTRY_NAME];
countriesFoundedBetween[j] = countryMatched;
System.out.println("countriesFoundedBetween: " + countriesFoundedBetween[j] + "; biggestCountries[i][COUNTRY_NAME]: " + biggestCountries[i][COUNTRY_NAME]);
}
}
}
return countriesFoundedBetween;
}