Which line contains the error?
public class Sample71
{
public static void main(String[] args)
{
int grade = 75;
switch (grade / 10)
{
case 7:
assert grade >= 70 && grade < 80;
case 6:
System.out.println("pass");
break;
default:
System.out.println("other");
}
}
}
Answer: C
The case 7 branch has no break, so control falls through into case 6 and prints pass by accident rather than by design. The assertion above it is true and passes. Fall-through is legal and occasionally intended, but here it makes the 70s share a branch with the 60s silently.
Please log in or register to report this question.