Learn AP Comp Sci

Problem of the Day

Thursday, December 4, 2025


Problem:

Consider the following code segment.

public static void singleten()
{
int x = 0;
for (int i = 0; i < 5; i++)
{
if ( /* condition */ )
System.out.println(10);
x += 2;
}
}

Which of the following conditions would result in a single 10 to be printed?

  1. x / 10 == 1
  2. i / 10 == 1
  3. i % 10 == 0
  1. I only
  2. II only
  3. III only
  4. I and II only
  5. Neither I, II, nor III

Show solution:

The correct answer is c. Choice I is incorrect because x runs from 0 to 8, never reaching the value of 10 that would be necessary for the condition to be true. The condition for Choice II is incorrect because i never reaches a value of 10, which would be necessary for the condition to be true. In choice III, when i has a value of 0 that condition is true, resulting in the 10 being printed.