我在JAVA程序里调用自己写的函数,出现这样的错,是什么原因non-static method g(x) cannot be reference from a static context,这是为什么阿,大家帮我看看
public static void main(String[] args) throws IOException
{
sigma+=g(x);
}
double g(double x)
{
return (x);
}
public static void main(String[] args) throws IOException
{
sigma+=g(x);
}
double g(double x)
{
return (x);
}
这个方法不是静态的,改成:
static double g(double x){
return x;
}