计算并输出10的阶乘。10的阶乘=10*9*8*7*6*5*4*3*2*1 ( 用JAVA)

如题所述

public class Test{

   public static void main(String[] args) {

  System.out.println(add(10));

 }

 public static int  add(int temp){

  return temp==1||temp==0?1:add(temp-1)*temp;

 }

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-21
public class Factorial {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println(Factorial.getValue(4));
}

public static long getValue(int num) {
if (num == 1)
return 1;
return num * Factorial.getValue(num - 1);
}

}
第2个回答  2010-09-21
vb我会 Java 不会 呵呵