JAVA exercise-output 1! +2! +...+10! sum

Analysis:
Use the for loop, the outer for loop determines the number of sums, and the inner for loop determines the factorial result for each time.

program:

public class Demo02ForTest {
    
    
    public static void main(String[] args) {
    
    
        int i,j,mul,sum =0;
        for ( i = 1; i <= 10 ; i++) {
    
    
            mul = 1;
            for ( j = 1; j <=i ; j++) {
    
    
                mul = mul * j;
            }
             sum = sum + mul;
        }
        System.out.println("1!+2!+...+10!之和:" + sum);
    }
}

Program demonstration:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44664432/article/details/108572920