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
Get step-by-step solutions from verified subject matter experts
