Tracing Nested For Loops
What is the output of the following code segment?
String output = "";
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
if (i > j) {
output += "*";
} else {
output += "-";
}
}
output += "\n";
}
System.out.print(output);
A
**
**
**
B
–
*-
**
C**
**
*-
D
–
-*
**
Question Leaderboard
Not enough data yet to show leaderboard.
