218k views
0 votes
Which of the following code segments will print “large enough” when the square of the number var is larger than 25?

if (Math.sqrt(var) 25)
{
System.out.println("large enough");
}

if (Math.sqrt(2, var) > 25)
{
System.out.println("large enough");
}

if (Math.sqrt(var) > 25)
{
System.out.println("large enough");
}
The Math.sqrt method finds the square root, not the square of a number.

if (Math.pow(var, 2) < 25)
{
System.out.println("large enough");
}

Which of the following code segments will print “large enough” when the square of-example-1
User Callombert
by
4.0k points

1 Answer

1 vote

Answer:

C.

if (Math.sqrt(var) > 25)

{

System.out.println("large enough");

}

Step-by-step explanation:

Analyzing each option:

(a): if (Math.sqrt(var) < 25)

The above condition uses < which means less than.

So, basically the condition checks if the square root of var is less than 25

This is not the required condition in the question

(b): if (Math.sqrt(2, var) > 25)

The above is an incorrect syntax of checking for square roots and it'll return an error when the program is run

To look for square root, make use of Math.sqrt(var)

(c): if (Math.sqrt(var) > 25)

As stated in the last statement of (b), the correct syntax to check for square root is Math.sqrt(var) and the condition above makes use of > which implies that if square root of var is greater than 25.

And if yes, it prints large enough

(d): if (Math.pow(var, 2) < 25)

This doesn't check for square root of var but rather it checks for var raise to power of 2.

So, from the analysis above;

Option c answers the question

User Hound
by
4.5k points