我使用的命令行參數爲這一個:Java我在這裏做錯了什麼?
public class Pg253E4 {
public static void main(String[]args) {
try {
System.out.println(Average.average(args)); // This part is saying I don't have a method in Average called average(String[] argName)
} catch(NullPointerException e) {
System.out.println(e.toString());
} catch(NumberFormatException e) {
System.out.println(e.toString());
} finally {
System.out.println("Nice job");
}
}
}
而這是其他類:
public class Average {
public static double average(String[] arrayString) throws NullPointerException,NumberFormatException {
double sum=0;
double arrayStorage[] = new double[arrayString.length];
for(int i = 0; i< arrayString.length; i++) {
arrayStorage[i] = Double.parseDouble(arrayString[i]);
}
for(int i = 0; i<arrayString.length; i++) {
sum += arrayStorage[i];
}
return (sum/arrayString.length);
}
}
我不明白爲什麼一個語法錯誤彈出說我的天堂在我明確表示的時候,我沒有在Average
課程中聲明或定義任何叫做average(String[] argName)
的方法。
在你的類路徑中是否平均? –
與'Pg253E4'在同一包中是'Average'?如果沒有'平均'被導入到'Pg253E4'? – ubiquibacon