//PS:num的值不能超过20,否则会溢出 //方法一 import java.util.Scanner; public class Test21{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("请输入一个数字:"); int num = input.nextInt(); long sum1 = 0; int i = num; do{ long sum2 = 1; while(num>0){ sum2 *= num--; } sum1 += sum2; num = --i; }while(i>0); System.out.println(sum1); } } //方法二 import java.util.Scanner; public class Test20{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("请输入数字:"); int num = input.nextInt(); long sum1=0; for(int i=1;i<=num;i++){ long sum2=1; for(int j=1;j<=i;j++){ sum2*=j; } sum1+=sum2; } System.out.println(sum1); } }