Nested Iteration

AP Computer Science A· difficulty 4/5

public static int run() {
    int x = 100;
    int c = 0;
    while (x > 1) {
        x = x / 2;
        c++;
    }
    return c;
}
// Call: System.out.println(run());

What is printed?

  • A

    10

  • B

    6

    check_circle
  • C

    7

  • D

    5

Explanation

100->50->25->12->6->3->1, six divisions.

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

Related questions