标签:public for循环 string pac symbol demo1 apache put imp
import java.util.*;
import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;
public class Demo13 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int jc = 1; // 6!=1*2*3*4*5*6=720
int he = 0;
System.out.println("请输入n的值:");
int n = input.nextInt();
for (int i = 1; i <= n; i++) {
jc *= i; // 1*1=1 1*2=2 2*3=6 6*4=24 24*5=120 120*6=720
he += jc;
}
System.out.println(n + "的阶层是:" + jc);
System.out.println("1!+..." + n + "!的值是:" + he);
}
}
初学者习题练习。从控制台输入一个数n,使用for循环实现求n! 提示:n! =n*(n-1)*(n-2)*…*1 升级:求1!+2!+3!+…+n!的值
标签:public for循环 string pac symbol demo1 apache put imp
原文地址:https://www.cnblogs.com/ztzz/p/12884268.html