The following if statement tests the rainfall in New York’s Central Park during the months of June, July and August.

if (low <= rain && rain <= high)
System.out.println("Rainfall amount is normal.");
else
System.out.println("Rainfall amount is abnormal.");
It could be replaced with:
I.

if (rain >= low)
{
if (rain <= high)
System.out.println("Rainfall amount is normal.");
}
else
System.out.println("Rainfall amount is abnormal.");
II.

if (rain >= low)
{
if (rain <= high)
System.out.println("Rainfall amount is normal.");
else
System.out.println("Rainfall amount is abnormal.");
}
else
System.out.println("Rainfall amount is abnormal.");
III.

if (rain >= low)
System.out.println("Rainfall amount is normal.");
else if (rain <= high)
System.out.println("Rainfall amount is normal.");
else
System.out.println("Rainfall amount is abnormal.");
I only
II only
III only
(II or III)
I, II or III

Respuesta :

Answer:

II only

Explanation:

In the original code, both conditions of low<=rain and rain >= high must be met for the print message to be executed. This is denoted by the && logical operator.

The code in II does the same thing. It first checks that the low <=rain condition is true; then it goes on to check if the rain >= high condition is true as well before the "normal" print statement can be executed. But if either of the condition is not true, it prints "abnormal" because both conditions must be true.

Otras preguntas