Learn AP Comp Sci

Problem of the Day

Friday, October 24, 2025


Problem:

Which of the following loops will print out the numbers 1-11, inclusive?


  1. int i = 1;
    while (i < 12)
    {
    System.out.println(i);
    i++;
    }

  2. int i = 1;
    while (i <= 11)
    {
    System.out.println(i);
    i++;
    }

  3. int i = 0;
    while (i < 11)
    {
    i++;
    System.out.println(i);
    }
  1. I only
  2. I and II only
  3. I and III only
  4. I, II, and II

Show solution:

The correct answer is d. All of them produce the required output, although loop I is the most common form.