这是下面的代码:
public class Country{
private String name;
private City [] cities;
private int index =0;
public Country (String n, int nrc){ // nrc as in number of cities
name = n;
cities = new City[nrc];
}
public boolean exists (City str){
for(int i =0; i>index;i++){
if(cities[i].equals(str)){
return true;
}
}
return false;
}
public void addCity (City str){
if(str == null){
System.out.print("City not initialized!");
}
if(exists(str)){
System.out.print("City exists!");
}
if(cities.length == index){
System.out.print("Not enough space in array!");
}
cities[index++] = str;
}
}
我想知道cities[index++] = str应该怎么做。任何人都可以帮忙吗?
海绵宝宝撒
忽然笑
相关分类