"population"配列のすべての集団を特定の最小値以上にして配列に戻すことになっています。私は私の新しい配列の要素の正しい量を取得し、最後の値を正しく割り当てることができますが、残りの値は0に戻ります!配列を既存の配列の要素に代入する
class Canada {
private String[] provinces;
private int[] populations;
private int[] array;
private int i;
public static final int NO_SUCH_PROVINCE = -1;
public static final int O = 0;
public static final int Q = 1;
public static final int BC = 2;
public static final int A = 3;
public static final int M = 4;
public static final int S = 5;
public static final int NS = 6;
public static final int NB = 7;
public static final int NL = 8;
public static final int PE = 9;
public static final int NT = 10;
public static final int Y = 11;
public static final int N = 12;
public Canada() {
provinces = new String[13];
provinces[O] = "Ontario";
provinces[Q] = "Quebec";
provinces[BC] = "British Columbia";
provinces[A] = "Alberta";
provinces[M] = "Manitoba";
provinces[S] = "Saskatchewan";
provinces[NS] = "Nova Scotia";
provinces[NB]= "New Brunswick";
provinces[NL] = "Newfoundland and Labrador";
provinces[PE] = "Prince Edward Island";
provinces[NT] = "Northwest Territories";
provinces[Y] = "Yukon";
provinces[N] = "Nunavut";
populations = new int[13];
populations[O] = 12851821;
populations[Q] = 7903001;
populations[BC] = 4400057;
populations[A] = 3645257;
populations[M] = 1208268;
populations[S] = 1033381;
populations[NS] = 921727;
populations[NB] = 751171;
populations[NL] = 514536;
populations[PE] = 142204;
populations[NT] = 141462;
populations[Y] = 33897;
populations[N] = 31906;
}
public int[] getPopulatiosnAboveMin(int min) {
int i = 0;
while(i < populations.length) {
if(populations[i] > min){
array = new int[i + 1];
array[i] = populations[i];
}
i++;
}
return(array);
}
}
マップとクラスを使用する必要があります。 – SLaks
新しいループを割り当てるたびに新しい配列を割り当て、最後のメンバーだけを入れても正しく表示されません。 – John3136