本帖最后由 feigecal 于 2012-6-26 21:15 编辑
class Circle
{
private static double pi=3.14;
private double radius;
public Circle(double r)
{
radius=r;
}
public static double compare(Circle[] cir)
{
int max = 0;
for(int x=1; x<cir.length; x++)
{
if(cir[x].radius>cir[max].radius)//这里为什么要加上.radius啊?求详解
max = x;
}
return cir[max].radius;
}
}
class Test2
{
public static void main(String[] args)
{
Circle cir[]=new Circle[3];
cir[0]=new Circle(1.0);
cir[1]=new Circle(2.0);
cir[2]=new Circle(4.0);
System.out.println("最大的半径值是:"+Circle.compare(cir));
}
} |
|