/*
获取指定数组的最大值
*/
class Circle
{
private static double pi = 3.14;
private double radius;
public Circle(double radius)
{
this.radius = radius;
}
public static double compare(Circle[] cir)//取出Circle[]数组的最大半径值
{
int max = 0;
for (int x=0; 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];
cir[0] = new Circle(1.0);
cir[1] = new Circle(2.0);
cir[2] = new Circle(3.0);
System.out.println("最大的半径值是"+Circle.compare(cir));
}
} |
|