此题怎么补?
补足compare函数内的代码,不许添加其他函数。
class Circle
{
private static double pi=3.14;
private double radius;
public Circle(double r)
{
radius=r;
}
public static double compare(Circle[] cir)0
{
//程序代码
}
}
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(4.0);
System.out.println("最大的半径值是:"+Circle.compare(cir));
}
}
------解决方案--------------------
public static double compare(Circle[] cir) {
//程序代码
double max = 0;
for (Circle c: cir) {
if (c.radius > max)
max = c.radius;
}
return max;
}
题目很垃圾,楼主也很不用功。