原谅我的无知。我是初学者:
为什么以下代码给我以下编译错误?[行:16] 不能从静态上下文引用非静态变量 x
public class average{
int [] numbers = {2,3,4,5,6};
double x = averageMark(numbers);
public static double averageMark(int [] numbers){
int sum = 0;
double average = 0.000;
for (int i = 0; i < numbers.length; i++){
sum = numbers [i] + sum;
average = sum/numbers.length;
}
return average;
}
public static void main (String [] args){
System.out.println(x);
}
}