for Loops

AP Computer Science A· difficulty 2/5

int total = 0;
for (int i = 10; i >= 1; i--) {
  total += i;
}
System.out.println(total);

What is printed?

  • A

    55

    check_circle
  • B

    45

  • C

    10

  • D

    50

Explanation

The loop adds 10+9+8+...+1 = 55 to total.

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

Related questions