Page 747 - AP Computer Science A, 7th edition
P. 747

9. (D) Each else gets paired with the nearest unpaired if. Thus when the test (22 % 5 == 0) fails, the else part indicating that 22 is negative will be executed. This is clearly not the intent of the fragment, which can be fixed using delimiters:
int num = calltoamethodthatreadsaninteger; if (num > 0)
{
if (num % 5 == 0) System.out.println(num);
} else
System.out.println(num + " is negative");





























































































   745   746   747   748   749