用java语句求N的阶乘

1.求10的阶乘。
public class Test {
 public static void main(String[] args) {

int n = 10;
  int result = 1;
  for (int i = 1; i <= n; i++) {
   result *= i;
  }
  System.out.println(result);

}

}

2.用java语句求n的阶乘

import java.util.Scanner;
public class Test {
 public static void main(String[] args) {
  Scanner cin = new Scanner(System.in);
  int n = cin.nextInt();
  int result = 1;
  for (int i = 1; i <= n; i++) {
   result *= i;
  }
  System.out.println(result);

}

}

 

posted on 2018-03-29 20:23  兮夜1234  阅读(1283)  评论(0编辑  收藏  举报

导航