Java Loop Printing Output
Which code snippet should be inserted as the missing line to print an asterisk (*) followed by a new line on each iteration of the loop?
public class PrintStars {
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
// missing line
}
}
}
A
printLine(“*”);
B
System.out.println(“*”);
C
System.out.print(“*”);
D
System.out.println(“*\n”);
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #2 | y.seong2027 | 1 | 1 | 0m 07s | 93 |
| #3 | Pelisx | 1 | 1 | 0m 19s | 81 |
| #4 | kimtrinhqldacamle | 1 | 1 | 0m 29s | 71 |
| #5 | hitrishabhatia | 1 | 4 | 0m 00s | 70 |
| #6 | suhanakochhar006 | 1 | 2 | 0m 51s | 39 |
| #7 | midnightasdark | 1 | 1 | 1m 07s | 33 |
| #8 | bommasam000 | 1 | 2 | 18m 50s | -1,040 |
Items per page:
10
1 – 8 of 8
APFIVE