Question: The PrimeFinder class below contains several static methods which are used to determine information about prime numbers. Prime numbers are positive integers which have exactly
The PrimeFinder class below contains several static methods which are used to determine information about prime numbers. Prime numbers are positive integers which have exactly two divisors (1 and themselves).

Coding Language: JAVA
public class PrimeFinder {
/** Returns the difference between num and the closest prime number which * is greater than or equal to num * Precondition: num is positive */ public static int gapToNextPrime(int num) { //ANSWER GOES HERE }
/** Returns true if the integer n is a prime number * Precondition: n is positive */ private static boolean isPrime(int n) { /* COMPLETE WORKING METHOD PROVIDED */ /* DO NOT MODIFY THE IMPLEMENTATION OF THIS METHOD*/ if(n
/* Methods for previous parts of this question are not shown */
-------------------------------------------------------------------------------------------------------
Help with this activity please!
(b) Write the gapToNextPrime method which returns the difference between the parameter num and the closest prime number which is greater than or equal to num . See the table below for examples of this method being used. Method call Value returned gapToNextPrime (9) 2 Explanation 11 is the next prime number after 9, the difference between 11 and 9 is 2. 17 itself is prime 97 is the next prime number after 90, the difference between 97 and 90 is 7. gapToNextPrime (17) 0 gapToNextPrime (90) 7 Complete the gapToNextPrime method below. You must use the isPrime method appropriately to receive full credit. /** Returns the difference between num and the closest prime number which is greater than or equal to num Precondition: num is positive */ public static int gapToNextPrime (int num)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
