Computer Applications
Write a program in Java to find the sum of the given series:
S = 1! + 2! + 3! + …. + n!
Java
Java Nested for Loops
65 Likes
Answer
import java.util.Scanner;
public class KboatSeries
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter n: ");
int n = in.nextInt();
long sum = 0;
for (int i = 1; i <= n; i++) {
long f = 1;
for (int j = 1; j <= i; j++) {
f *= j;
}
sum += f;
}
System.out.println("Sum = " + sum);
}
}
Output

Answered By
25 Likes
Related Questions
Write a program in Java to find the sum of the following series:
S = 1 + (3/2!) + (5/3!) + (7/4!) + ……. to n
Write a program in Java to display the following pattern:
a
ce
gik
moqsState whether the following statement is True or False :
When break statement is applied, it terminates the loop.
Write a program in Java to input the values of x and n and print the sum of the following series:
S = 1 - x2/2! + x4/4! - x6/6! + ……. xn/n!