public class GetMax {
//求数组最大值
public int Max (int[]shuzu)
{
int temp=0;
for(int i=0;i<=shuzu.length;i++)
{
if(shuzu[i]>temp)
{
temp=shuzu[i];
}
}
return temp;
}
public static void main(String[]args)
{
int [] shuzu={2,5,8,9,5,6,12,1};
int value=Max(shuzu);//这里为什么不能调用Max函数呢?
}
}
------解决思路----------------------
在静态上下文中调用的方法必须也是静态的。在Max方法上加上static修饰符就行了
------解决思路----------------------
这属于基础知识了,main是static的,而Max函数时非静态的,他的存在与否要看,所在的类是否被实例化。向楼上说的一样,你这样编译都过不去。