You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
363 B
11 lines
363 B
public class ShapeUtil {
|
|
// 统一打印面积的静态方法:支持所有Shape子类
|
|
public static void printArea(Shape shape) {
|
|
if (shape == null) {
|
|
System.out.println("图形不能为空!");
|
|
return;
|
|
}
|
|
double area = shape.getArea();
|
|
System.out.printf("图形面积为:%.2f%n", area);
|
|
}
|
|
}
|