class calcArea{
public static void main(String[] args)
{
int a,b;
double triArea,rectArea;
String s1,s2;
s1=args[0];
s2=args[1];
Triangle calcTri = new Triangle();
triArea = calcTri.calc(s1,s2);
Rectangle calcRect = new Rectangle();
rectArea = calcRect.calc(s1,s2);
System.out.println("長 = "+s1);
System.out.println("高 = "+s2);
System.out.println("三角形面積 = "+triArea);
System.out.println("長方形面積 = "+rectArea);
}}
class Triangle{
Triangle()
{
//System.out.println("三角形面積");
}
static int calc(String s1, String s2){
int x,y,z;
x = Integer.parseInt(s1);
y = Integer.parseInt(s2);
z = x * y /2;
return z;
}}
class Rectangle{
Rectangle()
{
//System.out.println("長方形面積");
}
static int calc(String s1, String s2)
{
int x,y,z;
x = Integer.parseInt(s1);
y = Integer.parseInt(s2);
z = x * y;
return z;
}}
沒有留言:
張貼留言