Project 91: Prime Factors

Project 91: The variable 'n' has been initialized.  There is also a working method called isItPrime available.

isItPrime(5) returns true because 5 is prime.

isItPrime(15) returns false because 15 is not prime (5x3).

Task: Assign the array 'primeFactors' to contain the prime factors of n.  The variable 'primeFactors' has already been created and begins empty.

Example 1:  Suppose 'n' was randomly assigned to hold the value 18.  The array primeFactors should hold the values shown below.

                  [2, 3]

Example 2:  Suppose 'n' was randomly assigned to hold the value 100.  The array primeFactors should hold the values shown below.

                  [2, 5]

Example 3:  Suppose 'n' was randomly assigned to hold the value 210.  The array primeFactors should hold the values shown below.

                  [2, 3, 5, 7]

Note: Remember the push method adds a value to the end of an array.

x.push(5);

x.push(7);

//x holds the values [5, 7]

Note: If you are coding in Java, you can assume that 'primeFactors' has been declared and initialized to be an empty ArrayList.

**If your code works for 5 test cases, you can enter your e-mail address

Universal Computational Math Methods:

pow(5,2) returns 25.0

abs(-3.0) returns 3

sqrt(49.0) returns 7.0