interface IShape{
public double area();
}
class Circle implements IShape{
private double r;
public Circle(double r){
this.r =r;
}
public double area(){
return 3.14*r*r;
}
}
class Rectangular implements IShape{
private double whith;
private double height;
public Rectangular(double whith,double height){
this.whith=whith;
this.height=height;
}
public double area(){
return whith*height;
}
}
public class TestPrintArea{
public static void PrintArea(IShape shape){
System.out.println(shape.area());
}
public static void main(String[] args){
PrintArea(new Circle(3));
PrintArea(new Rectangular(4,5));
}
}
照着上面加 三角行,和梯形,面积公式要查一下!
控制输入就自己写了 (
BufferedReader in = new BufferdReader(new InputStreamReader(System.in));
String stdin = in.radLine().trim();
这下来要看你在怎要求输入了
1.一次性输入中间空格 ; 圆形 10
则要对stdin 处理 取出 圆形 和半径,
if(输入==圆形)
//do
if ()//自己写
2 另外分布输入
if(输入=圆形){
打印("请输入半径")
BufferedReader in = new BufferdReader(new InputStreamReader(System.in));
}
if(输入 = 矩形){
//自己写
}
温馨提示:答案为网友推荐,仅供参考