Question: Write a static method called isPrime . This method takes a single int parameter num . The return type is boolean . It returns true

Write a static method called isPrime. This method takes a single int parameter num. The return type is boolean. It returns true if the number is prime, and false, otherwise. You need to write both the method header and the method body.

HINT: You can reuse your code from the previous problem. Compute a list of all of the factors of num. If there are only two unique factors, then num is prime; otherwise num is not prime.

HINT: you can use the size method to get the size of an ArrayList

Sample Input 1:

20

Sample Output 1:

false

Sample Input 2:

1

Sample Output 2:

false

Sample Input 3:

5

Sample Output 3:

true

Sample Input 4:

2

Sample Output 4:

true

Sample Input 5:

3

Sample Output 5:

true

Sample Input 6:

4

Sample Output 6:

false

Step by Step Solution

3.39 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure Heres the static method isPrime pu... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!