Monday, August 28, 2017

Write a java program that finds and stores the factorials of numbers between and including 3 and 10 in an array and calculates the average of the factorials from the array.

/*
For more exercises,
visit shegertech.blogspot.com
or
shegertech.com
Author: Eyasu M.
Email: eyasu@india.com
*/

public class FactorialAverage {
    public static void main(String[] args) {
        int factorial;
        double sum = 0;
        int[] x = new int[8];
        for (int i = 3, k = 0; i <= 10; i++, k++) {
            factorial = 1;
            for (int y = 1; y <= i; y++) {
                factorial *= y;
            }
            x[k] = factorial;
            sum += x[k];
        }
        System.out.println(sum / x.length);
    }
}

Output


Share: