Sum of Factorial Series
This program calculates sum of factorials from 1! to 6!.
Problem Statement
Write a Java program that calculates sum of factorials from 1! to 6! using nested for loop.
Source Code
| 1 | public class SumFactorials { |
| 2 | public static void main(String[] args) { |
| 3 | int sum = 0; |
| 4 | for(int n=1; n<=6; n++) { |
| 5 | int fact = 1; |
| 6 | for(int i=1; i<=n; i++) { |
| 7 | fact *= i; |
| 8 | } |
| 9 | sum += fact; |
| 10 | } |
| 11 | System.out.println("Sum of factorials = " + sum + " - Eduinq"); |
| 12 | } |
| 13 | } |
Program Output
Sum of factorials = 873 - Eduinq
Explanation
The outer loop iterates numbers 1 to 6, inner loop calculates factorial, and result is added to sum. This demonstrates nested loops for factorial series summation. Shows how nested loops can calculate sum of factorial series.