java计算1-10阶乘的和

// 计算1-10阶乘的和
public class Work7 {

public static void main(String[] args) {
    int factorial = 1;
    int sum = 0;
    for (int i = 1; i <= 10; i++) {
        for (int j = 1; j <= i ; j++) {
            factorial *= j;    // get factorial
        }
        sum += factorial;      // sum factorial
        factorial = 1;
    }
    System.out.println(sum);
    // 4037913
}

}

posted @ 2022-03-22 12:21  花痴dy  阅读(1802)  评论(0编辑  收藏  举报