For 循环语句(100的阶乘代码)

来源:互联网 发布:调音器软件 编辑:程序博客网 时间:2024/06/05 16:49

public class Test2 {
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  double factorial = 0; // 需要用double类型,long类型会溢出
  double n = 1;

 

  for (int i = 1; i <= 99; i++) {
   n = n * i;
   factorial = n;
  }
  System.out.println("99的阶乘 =" + factorial);
 }

}

原创粉丝点击