Correct, the answer is B.
If the question's source code is executed, it will throw the following exception:
- Exception in "main" thread java.lang.Error: Unresolved compilation issue:
continue cannot be used outside of a loop
The continue statement cannot be used outside of a loop, as described in the documentation. When commenting the continue statement line, the code compiles normally and then print "Thank You! 500.0"
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
To test:
public static void main(String[] args) {
int price = 1000;
int qty = 2;
String grade = "2";
double discount = 0.0;
switch(grade) {
case "1":
discount = price * 0.1;
break;
case "2":
discount = price * 0.5;
//continue;
default:
System.out.println("Thank You!");
}
System.out.println(discount);
}
The answer is the letter B, notice that on line 16 the command ends with ":" instead of ";" causing the code not to compile. commenting out the line the code compiles normally.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
carloswork
2 months, 2 weeks agoiSnover
3 months agoalex_au
3 months ago