Question 131
What is printed?
int score = 78;
String grade = "";
if (score >= 90) {
grade = "A";
} else if (score >= 80) {
grade = "B";
} else if (score >= 70) {
grade = "C";
} else {
grade = "F";
}
int bonus = score % 10;
if (bonus >= 5) {
grade = grade + "+";
}
System.out.println(grade + " " + bonus);Main Solution
Step-by-step trace:
score = 78,grade = ""- Check
score >= 90: 78 >= 90 → false - Check
score >= 80: 78 >= 80 → false - Check
score >= 70: 78 >= 70 → true →grade = "C" bonus = score % 10 = 78 % 10 = 8- Check
bonus >= 5: 8 >= 5 → true →grade = grade + "+" = "C+" System.out.println(grade + " " + bonus)prints: C+ 8
The correct answer is D: C+ 8.
Teacher Explanation
This question tests students' ability to trace through a multi-branch if/else-if/else structure and a subsequent if statement. The key insight is that 78 falls in the 70–79 range (grade = "C"), and 78 % 10 = 8, which is ≥ 5, so a "+" is appended. The final println concatenates the modified grade string with a space and the integer bonus value.
Education Coach Advice
When tracing if/else-if chains, evaluate each condition in order and stop at the first true branch. Then continue tracing any subsequent (separate) if statements — they are not part of the else-if chain. Also remember that % gives the remainder, not a rounded value. Write out each variable's value after each step to avoid errors.
Traps
Common traps:
- Option A (B 8): Students may think 78 rounds up to the 80s range, triggering the
score >= 80branch. But 78 is strictly less than 80, so this branch is skipped. - Option B (C 8): Students may correctly identify grade as "C" but forget to check the bonus condition. Since 8 >= 5, the "+" is appended.
- Option C (B+ 8): Combines both errors — wrong grade letter AND correct bonus logic.
Answer images

