Question: 3) Consider the following JAVA method. This method receives an integer and then returns true or false. Suppose we call this method as follows: boolean

3) Consider the following JAVA method. This method receives an integer and then returns true or false. Suppose we call this method as follows:

boolean x = prm(25);

boolean y = prm(17);

What would be x and y after calling the method? Trace the code and show the result step-by-step.

public static boolean prm(int n)

{

if (n <= 1)

return false;

if (n == 2)

return true;

for (int i = 2; i <= Math.sqrt(n) + 1; i++) // Math.sqrt(n) returns the rounded square root of n

{

if (n % i == 0)

return false;

}

return true;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!