Casting and Ranges of Variables

AP Computer Science A· difficulty 3/5

public static int run() {
    int a = 9;
    int b = 4;
    int q = a / b;
    int r = a % b;
    return q * 10 + r;
}
// Call: System.out.println(run());

What is printed?

  • A

    21

    check_circle
  • B

    23

  • C

    13

  • D

    11

Explanation

9/4 = 2, 9%4 = 1. 2*10 + 1 = 21.

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

Related questions