java计算面积的方法_JAVA多态计算面积main函数调用方法
public static void main(String[] args) {
Shape shape;
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)選擇圖形(1、圓形 2、矩形 3、三角形)");
int a = input.nextInt();
if(a == 1){
System.out.println("請(qǐng)輸入圓形的邊長:");
double r = input.nextDouble();
shape = new Round(r);
shape.area();
}else if(a == 2){
System.out.println("請(qǐng)輸入矩形的底:");
double bottom = input.nextDouble();
System.out.println("請(qǐng)輸入矩形的高:");
double high = input.nextDouble();
shape = new Rectangle(bottom, high);
shape.area();
}else if(a == 3){
System.out.println("請(qǐng)輸入三角形的底:");
double bottom = input.nextDouble();
System.out.println("請(qǐng)輸入三角形的高:");
double high = input.nextDouble();
shape = new Triangle(bottom, high);
shape.area();
}
input.close();
}
總結(jié)
以上是生活随笔為你收集整理的java计算面积的方法_JAVA多态计算面积main函数调用方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 批量验证_正则表达式批量验证函
- 下一篇: java 生成缩略图类_JAVA生成【缩