Factorial project Download

Javaclass.info

for loops, nested loops Student approved


Introduction

This lab is designed to give you practice tracing through nested for loops.


Task

Given an array of ints, calculate the sum of the factorials of all elements in the array.

You may use any array that you want to demonstrate this project but do not hard code anything!


Starter code

class Factorial{
	public static void main(String[] args){
		int[] j = new int[3];
		j[0] = 2;
		j[1] = 3;
		j[2] = 4;

		int fact = calculateFactorial(j);
	}

	static int calculateFactorial(int[] arr){
		/*		Your code here 		*/
	} 
}

Expected output

// With the input array: 
int[] j = new int[3]; 
j[0]= 2; 
j[1]= 3;
j[2] = 4;

// You'd expect: 
32		// = 2! + 3! + 4!

Useful tools to solve the problem