for Loops

AP Computer Science A· difficulty 3/5

int product = 1;
for (int i = 1; i <= 4; i++) {
  product *= i;
}
System.out.println(product);

What is printed?

  • A

    24

    check_circle
  • B

    10

  • C

    12

  • D

    120

Explanation

Starting from 1, the loop multiplies by 1, 2, 3, 4 giving 1<em>1</em>2<em>3</em>4 = 24 (which is 4!).

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

Related questions