for Loops

AP Computer Science A· difficulty 2/5

int count = 0;
for (int i = 1; i <= 20; i++) {
  if (i % 2 == 1) {
    count++;
  }
}
System.out.println(count);

What is printed?

  • A

    10

    check_circle
  • B

    11

  • C

    20

  • D

    9

Explanation

Odd numbers from 1 to 20 are 1, 3, 5, 7, 9, 11, 13, 15, 17, 19 — exactly 10 numbers.

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

Related questions