In this project, I have to use arrays to save the country codes and search their codes. The following codes do not show any errors. However, "NO records" can't be outputted and even output "null" when I search the unsaved country by the searchCountryCode method. How can I correct it to print out "No record"?
public static void createCountryCode(String countryName, String countrycode) {
if (nameCounter >= 20) {
System.out.println("Full");
} else {
System.out.println(countryName + ":" + countryCode);
}
countryNameRec[countryNameCounter++] = countryName;
countryCounterRec[countryCounter++]= countryCode;
}
public static void searchCountryCode(String countryName) {
boolean searchCountry = false;
int i = 0;
while (i<=20) {
if (countryNameRec[i].equals(CountryName)) {
searchCountry=true;
break;
}
i++;
}
if (!searchCountry) {
System.out.println("No Records");
}else {
System.out.println("The country code : "+ countryNameRec[i]+ " is: "+ countryCodeRec[i]); }
}
Aucun commentaire:
Enregistrer un commentaire