public static void main(String[] args) {
Shape shape;
Scanner input = new Scanner(System.in);
System.out.println("请选择图形(1、圆形 2、矩形 3、三角形)");
int a = input.nextInt();
if(a == 1){
System.out.println("请输入圆形的边长:");
double r = input.nextDouble();
shape = new Round(r);
shape.area();
}else if(a == 2){
System.out.println("请输入矩形的底:");
double bottom = input.nextDouble();
System.out.println("请输入矩形的高:");
double high = input.nextDouble();
shape = new Rectangle(bottom, high);
shape.area();
}else if(a == 3){
System.out.println("请输入三角形的底:");
double bottom = input.nextDouble();
System.out.println("请输入三角形的高:");
double high = input.nextDouble();
shape = new Triangle(bottom, high);
shape.area();
}
input.close();
}
时间: 2024-10-28 06:43:41