close
很好。為了中年人的尊嚴,咱要努力寫下去。老師很陰險的激勵大家,上課會統計大家交作業和出席的情況,根據英國研究,只要放棄了一次交作業,後面交作業機率幾乎等於零。俺以身試驗,目前堪稱為"顯著"。在台大上課就是同學大多很優秀,跟不上就旁邊涼快去,為了中年人的尊嚴,要艱苦地跟上。

輸入1~3個參數,如果是一個輸入,辨識回求圓形面積,兩個參數求矩形面積,三個參數求梯型面積。

public class PT62 {
    public static void main(String[] args)
    {
    double result = 0.0;
    String type = "";
    Area area= new Area();
    int [] input = new int [args.length];
    for (int i=0; i<args.length; i++)
    {
    input[i] = Integer.parseInt(args[i]);
    }
    if (args.length==1)
    {
    result = area.countarea(input[0]);
    type = "圓形";
    }
    else if (args.length==2)
    {
    result = area.countarea(input[0], input[1]);
    type = "矩形";
    }
    else if (args.length==3)
    {
    result = area.countarea(input[0], input[1], input[2]);
    type = "梯形";
}
System.out.println(type+"面積是"+result);
}
}
class Area
{
public double countarea(int r)
{
return (r*r*3.14);
}
public double countarea(int width, int height)
{
return (width*height);
}
public double countarea(int upper, int base, int height)
{
return ((upper+base)*height/2);
}
}
跑出來結果就是這樣啦!

 收工。
arrow
arrow
    全站熱搜

    brianc18 發表在 痞客邦 留言(0) 人氣()