标签:错误 bsp print 正整数 asn factorial 练习 int 程序
1 import java.util.Scanner; 2 3 public class Factorial { 4 public static void main(String[] args) { 5 long t = 1; 6 long sum = 0; 7 Scanner sc = new Scanner(System.in); 8 if(sc.hasNextInt()){ ////判断输入值是否为int类型 9 int n = sc.nextInt(); 10 for (int i = 1; i <= n; i++) { 11 for (int j = 1; j <= i; j++) { //计算n的阶乘 12 t *= j; 13 } 14 sum += t; 15 t = 1; 16 } 17 System.out.println("小于整数:"+n+"的所有正整数阶乘之和是:"+sum); 18 } 19 else 20 System.out.println("输入错误!"); 21 } 22 }
标签:错误 bsp print 正整数 asn factorial 练习 int 程序
原文地址:https://www.cnblogs.com/Iolo/p/11940978.html