java 按下列要求编写一个完整的基于application(应用)的程序:

A)接收命令行参数传递的浮点数,x, y和整数 n。
B)用递归技术编写方法用于计算n!。
C)利用公式:计算 并输出。

shapeArea.java
----------------------------------------
public interface shapeArea{
public double getArea();
public double getPerimeter();
}
----------------------------------------

Rectangle.java
----------------------------------------

import java.lang.*;
class Rectangle implements shapeArea{
private double width;
private double height;
public Rectangle(double w,double h){
width = w;
height = h;
}
public double getArea(){
return width * height;
}
public double getPerimeter(){
return width*2 + height*2;
}
public void toString0(){
//”width=1.0,heigth=2.0,perimeter=6.0,area=2.0"
System.out.print("width= ");
System.out.print(width);
System.out.print(",");
System.out.print("height= ");
System.out.print(height);
System.out.print(",");
System.out.print("perimeter= ");
System.out.print(getPerimeter());
System.out.print(",");
System.out.print("area= ");
System.out.print(getArea());
System.out.println("");
}
}
----------------------------------------
Test.java
----------------------------------------

class Test{
public static void main(String[] arg){
Rectangle aa = new Rectangle(100.1, 200.2);
aa.toString0();
}
}
----------------------------------------
汗 初级中的初级题的初级的解答

-------------------------------------
个人习惯 如果输出形式变了 以后好修改
System.out.println(""); 是打回车换行

偶然发现相关问题里有90%一样的问题 早知道不手打了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-30
public class Du{

public static void main(String[] args) throws Exception {

if(args == null || args.length < 3){
throw new Exception("Less than 3 parameter passed! Error!");
}

double x = Double.parseDouble(args[0]);
double y = Double.parseDouble(args[1]);
int n = Integer.parseInt(args[2]);

long fac = calcFac(n);
System.out.println(n + "! = " + fac);
}

private static long calcFac(int n) {
if(n == 1){
return 1;
}else{
return calcFac(n-1) * n;
}

}

}

------------------
C:\Program Files\IBM\RAD 7\jdk\bin>java Du
Exception in thread "main" java.lang.Exception: Less than 3 parameter passed! E
ror!
at Du.main(Du.java:6)

C:\Program Files\IBM\RAD 7\jdk\bin>java Du 3.2 1.57 5
5! = 120

C:\Program Files\IBM\RAD 7\jdk\bin>