Question: public class PrimeChecker { / / Returns 0 if value is not prime, 1 if value is prime public static int isPrime ( int testVal,
public class PrimeChecker
Returns if value is not prime, if value is prime
public static int isPrimeint testVal, int divVal
Base case : and are not prime, testVal is not prime
Base case : testVal only divisible by testVal is prime
Recursive Case
Check if testVal can be evenly divided by divVal
Hint: use the operator
If not, recursive call to isPrime with testVal and divVal
public static void mainString args
int primeCheckVal; Value checked for prime
Check primes for values to
for primeCheckVal ; primeCheckVal ; primeCheckVal
if isPrimeprimeCheckValprimeCheckVal
System.out.printlnprimeCheckVal is prime.";
else
System.out.printlnprimeCheckVal is not prime.";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
