Computer Science, asked by Aayushi99, 1 year ago

Write a program using Java to find 1!+2!+3!+4!+5!

Answers

Answered by TPS
2
public class SumOfFactorials {

    public static void main(String[] args) {
        int s = 0;
        for (int i = 1; i<=5; i++){
            int fact = 1;
            int x = 1;
            while (x<=i){
                fact = fact*x;
                x++;
            }
            s = s + fact;
        }
        System.out.println("The sum of the factorials is " + s);
    }

}


Similar questions