Java Nested Loop Output
What is printed when the following code segment is executed?
for (int r = 3; r > 0; r--)
{
int c;
for (c = 1; c < r; c++)
{
System.out.print("-");
}
for (c = r; c <= 3; c++)
{
System.out.print("*");
}
System.out.println();
}
A
–*
-**
B
–*
–*
C
*–
**-
D
-**
–*
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hitrishabhatia | 1 | 3 | 0m 00s | 80 |
| #2 | y.seong2027 | 1 | 2 | 0m 56s | 34 |
| #3 | kazvin.tjakradinata | 2 | 2 | 2m 49s | 31 |
| #4 | suhanakochhar006 | 1 | 2 | 2m 22s | -52 |
| #5 | chunxiangxu.cxu | 0 | 1 | 8m 56s | -546 |
| #6 | namansoin000 | 0 | 1 | 15m 44s | -954 |
| #7 | bommasam000 | 3 | 7 | 1h 28m | -5,067 |
Items per page:
10
1 – 7 of 7
APFIVE