Page 1 of 1

Fill in the code for this program to calculate the first 100 prime numbers. Each block of comments should have a line of

Posted: Tue Jul 12, 2022 8:19 am
by answerhappygod
Fill in the code for this program to calculate the first 100prime numbers. Each block of comments should have a line of codeperforming that action described.(Each line of code is 2points)
//Declare class called primeNumbers
//Declare array of 100 ints called primes
//Begin main method
//Start by assigning 2 to the first spot in the array
//Create loop to initialize the rest of the array
//Call nextPrime method to fill the next array spot (to speed upthe process, call nextPrime method with the previous index
//calculated and the current value of i)
//End of loop and main method (just print the value at atprimes[99] so we can check it against the expected value
//Begin nextPrime method that takes in the int 'p' (previousindex) and returns an int 'n'(next prime)
//initialize n to p+1
//initialize counter to i-1
//Start a while loop to check numbers until we reach the nextprime
//Check whether number is prime (Note: Since we have allprevious primes in the array, we only need to check againstthem)
//if n is evenly divisible by the current prime being checked,we need to increment n and reset the counter back to i-1
//Check if n is evenly divisible
//Increment n
//reset counter
//else we decrease counter by 1
//if counter gets below 0, we have found our prime, and the loopcan end, returning p
in java