Question 351
int c = 0;
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (i + j < 5)
{
c++;
}
}
}
System.out.println(c);
What is printed when the code segment executes?Main Solution
Solution:
Answer: A. The count is the number of pairs (i, j) with 0 <= i, j < 5 and i + j < 5. Row i = 0 contributes 5 pairs; i = 1, 4 pairs; i = 2, 3; i = 3, 2; i = 4, 1. Total: 5 + 4 + 3 + 2 + 1 = 15. This is the triangular number T5.
Answer: Correct: A
Answer images

