Which of the following program fragments will produce this output? (Ignore
spacing.)
2 - - - - -
- 4 - - - -
- - 6 - - -
- - - 8 - -
- - - - 10 -
- - - - - 12
I for (int i = 1; i <= 6; i++)
{
for (int k = 1; k <= 6; k++)
if (k == i)
System.out.print(2 * k);
else
System.out.print("-");
System.out.println();
}
II for (int i = 1; i <= 6; i++)
{
for (int k = 1; k <= i - 1; k++)
System.out.print("-");
System.out.print(2 * i);
for (int k = 1; k <= 6 - i; k++)
System.out.print("-");
System.out.println();
}
III for (int i = 1; i <= 6; i++)
{
for (int k = 1; k <= i - 1; k++)
System.out.print("-");
System.out.print(2 * i);
for (int k = i + 1; k <= 6; k++)
System.out.print("-");
System.out.println();
}
(A) I only
(B) II only
(C) III only
(D) I and II only
(E) I, II, and III