爲什麼我無法將appleArray,blueberryArray和peanutArray發送到calcTotalPies方法?無法將數組傳遞給方法
final int MAX_PIES = 81;
final int MAX_PER_TYPE = 27;
String typeOfPie = getPieType();
while (!typeOfPie.equalsIgnoreCase("q")) {
if (typeOfPie.equalsIgnoreCase("apple")) {
String[] appleArray = fillApple(typeOfPie, MAX_PER_TYPE);
}
else if (typeOfPie.equalsIgnoreCase("blueberry")) {
String[] blueberryArray = fillBlueberry(typeOfPie, MAX_PER_TYPE);
}
else if (typeOfPie.equalsIgnoreCase("peanut")) {
String[] peanutArray = fillPeanut(typeOfPie, MAX_PER_TYPE);
}
typeOfPie = getPieType();
}
if (typeOfPie.equalsIgnoreCase("q")) {
int totalPies = calcTotalPies(appleArray, blueberryArray, peanutArray);
}
只是爲了添加評論@丹:像Java和C語言中有一個叫做概念*「塊範圍*」。代碼塊由大括號分隔。塊範圍確保塊內聲明的變量不會污染它們出現的其他代碼域的名稱空間。這使您的項目中的模塊保持彼此分離。 – scottb