Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The object of this program is to determine the set of prime numbers between 2 an

ID: 3642601 • Letter: T

Question

The object of this program is to determine the set of prime numbers between 2 and 100. There are 25 of these. Once our program determines what they are, it will print the result to the screen. To determine if a given number is prime or not, simply divide it by all of the primes that are less than itself. If any of them evenly divide the number, i.e., with no remainder, then the number is not prime. If none of those lower primes evenly divide the number, then the number is prime.
As we discover new primes, our program will keep a list of them in a partial array. A partial array is an array that contains fewer data items in the array than the size of the array.

Your program should do the following:

1) Instantiate an integer array of size at least 25. (primeArray [25])
a) Set the first element to 2 and the counter numOfPrimes to 1. (numOfPrimes will track how many primes are in the partial array.)

2) Create a loop that increments index from 3 to 100
a) If index is prime, add it to the prime array. Use the method to determine if prime or not - public static boolean isPrime (int numToCheck, int [] currPrimes, int numOfPrimes)
i) Set primeArray [numOfPrimes] to the newly discovered prime.
ii) Increment numOfPrimes.

3) After filling the prime array with all of the primes between 2 and 100, print them out to the screen

The three input parameters are: (a) the number to check, (b) an integer array that contains the primes we

Explanation / Answer

public class PrimeArray { public static boolean isPrime (int numToCheck, int [] currPrimes, int numOfPrimes){ boolean flag = true; for (int j = 0; j