Question: Write a static method called checkPrime that takes an integer n as a parameter and that checks how many factors n has, returning true if
Write a static method called checkPrime that takes an integer n as a parameter and that checks how many factors n has, returning true if it is prime (exactly 2 factors) and returning false otherwise. Recall that a factor is a number between 1 and n that goes evenly into n and that prime numbers are those that have exactly two factors (1 is not a prime). So if we make the following call:
boolean test = checkPrime(24);
The method should produce the following two lines of output:
factors of 24 = 1, 2, 3, 4, 6, 8, 12, 24 Total factors = 8
and the variable test would be set to false because this number does not have exactly 2 factors.
Step by Step Solution
There are 3 Steps involved in it
Sure Heres a possible implementation of the checkPrime method public static boolean checkPrimeint n ... View full answer
Get step-by-step solutions from verified subject matter experts
