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)
max = x;
}
return cir[max].radius;
}
}
class TC
{
public static void main(String[] args)
{
Circle cir[]=new Circle[3];
System.out.println("最大的半径值是:"+Circle.compare(cir));
}
}
问题:
代码第四行private double radius;存在的原因,radius不可以定义到public Circle(double r)函数内吗?
或者更进一步直接在public static double compare(Circle[] cir)函数内输入radius?????? |
|