Expressions and Assignment Statements

AP Computer Science A· difficulty 2/5

public static double calc() {
    int a = 7, b = 2;
    double c = a / b + 0.5;
    return c;
}
// Call: System.out.println(calc());

What is printed?

  • A

    4.5

  • B

    3.5

    check_circle
  • C

    4.0

  • D

    3.0

Explanation

a/b is integer division: 7/2 = 3. Then 3 + 0.5 = 3.5 stored in double.

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

Related questions