Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
public class Main {
static int discount(int price) {
return price / 10;
System.out.println("discount computed");
}
public static void main(String[] args) {
System.out.println(discount(500));
}
}
- A price must be double
- B The println comes after return in the same block, so it is unreachable – javac rejects it Correct
- C Methods cannot print
- D return needs parentheses
Correct Answer: Option B
Move the println before the return.
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!