The following loop displays _______________.

for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
i++;
}

a. 1 2 3 4 5 6 7 8 9
b. 1 2 3 4 5 6 7 8 9 10
c. 1 2 3 4 5
d. 1 3 5 7 9
e. 2 4 6 8 10

d In this for loop, i is initialized to 1 . i++ adds 1 to i at the end of the iteration. In the action-after-each-iteration, i is again incremented by 1 . So, i is in effect incremented twice. So, i is 1, then 3, 5, 7, and 9.
The correct answer is D.

Computer Science & Information Technology

You might also like to view...

Adjusting the transparency of an image permits some of the slide background to be seen through the placeholder background

Indicate whether the statement is true or false

Computer Science & Information Technology

Users who are more advanced can also take a blog from a site such as Blogger or WordPress and link it to Facebook ________

A) Friends B) Events C) Notes D) Links

Computer Science & Information Technology