Which of the following program fragments will produce this output? (Ignore Spacing)
2-----
-4----
--6---
---8--
----10-
-----12
Imagine if the rows and columns were perfectly aligned.
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("");
}
How is the code fragment above going to print that?
2-
-
-
-
-
-
4-
The above is... what I believe the code fragment should print because I'm not sure where the pointer indicating where I insert the next symbol goes after looping the inner loop once by increasing k from 1 to 6. How am I wrong?