Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
public static void main(String[] args) {
int stock = 0;
if (stock == 0) {
System.out.println("out of stock");
continue;
}
System.out.println("in stock");
}
}
- A if needs else
- B continue is only allowed inside a loop; to leave main early use return Correct
- C stock must be boolean
- D println cannot be in if
Correct Answer: Option B
break is also only allowed in loops, switches or labelled statements.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!