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?
x / 10 == 1i / 10 == 1i % 10 == 0
- I only
- II only
- III only
- I and II only
- Neither I, II, nor III
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.