Factorial Summation Series
This program calculates sum of factorials from 1! to 7!.
Problem Statement
Write a Java program that calculates sum of factorials from 1! to 7! using nested for loop.
Source Code
| 1 | public class FactorialSummation { |
| 2 | public static void main(String[] args) { |
| 3 | int sum = 0; |
| 4 | for(int n=1; n<=7; 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 = 5913 - Eduinq
Explanation
The outer loop iterates numbers 1 to 7, inner loop calculates factorial, and result is added to sum. This demonstrates factorial summation using nested loops. Shows how nested loops can calculate factorial summation series.