我的代碼沒有編譯給我的錯誤是「非靜態方法sumArray(double [])不能從靜態上下文中引用」。我試圖弄清楚這一點,但我不知道我需要改變。請幫助,讓我知道錯誤是什麼。在其他方法中的Java錯誤消息數組
import java.util。*; 公共類Homework5 {
public static void main(String[] args)
{
Scanner key = new Scanner(System.in);
System.out.println("How many numbers would you like in the array?");
int arrayLength = key.nextInt();
Homework5 inst1 = new Homework5();
double[] numbers = new double[arrayLength];
System.out.println("Enter " + arrayLength + " numbers:");
for(int i=0; i < arrayLength; i++)
{
numbers[i] = key.nextDouble();
}
System.out.println("The sum is "+sumArray(numbers));
}
public double sumArray(double[] newArray)
{
double total=0;
for(int index = 0; index < newArray.length ; index++)
{
total = total+newArray[index];
}
return total;
}
}