十以内阶乘

 

import java.util.Scanner;


public class 阶乘 {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("输入一个数字");

int n = sc.nextInt();

System.out.println("结果为:"+f(n));

 

}
public static int f(int n){

int sum = 1;

for(int i = 1;i <= n;++i){

sum *= i;

}

return sum;

}

posted @ 2018-03-28 21:51  关菁。  阅读(244)  评论(1编辑  收藏  举报