public class Demo4{ public static void main(String[] args) { int sum = 0; /*1!+2!+3!+4!+...+20! 2!= 2*1! 3! = 3*2!*/ int a = 1; for (int i=1;i<=20;i++) { a *= i;//a = 1 a= 1!*2 = 2! a= 3*a = 3*2!=3! sum += a; } System.out.println(sum); //9 99 999 9999 99999... //9 9*10+9 99*10+9 //9 9*10+9 9*100+99 9*1000+999 long sum1 = 0; long b = 0; for (int i=1;i<=10;i++) { b = b*10+9;//b= 9 b= 9*10+9=99 b= 99*10+9 sum1 += b; } System.out.println(sum1); } }