Casting and Ranges of Variables

AP Computer Science A· difficulty 3/5

public static String grade(int s) {
    if (s >= 90) return "A";
    else if (s >= 80) return "B";
    else if (s >= 70) return "C";
    else return "F";
}
public static String run() {
    return grade(85) + grade(70) + grade(95);
}
// Call: System.out.println(run());

What is printed?

  • A

    BCC

  • B

    BCA

    check_circle
  • C

    ABC

  • D

    BBA

Explanation

grade(85)="B", grade(70)="C", grade(95)="A". Concatenated: "BCA".

Want 10 more like this — adaptive to your weak spots?

Related questions