What is the output for y?
int y = 0;
for (int i = 0; i < 10; ++i) {
y += i;
}
System.out.println(y);
a. 10
b. 11
c. 12
d. 13
e. 45
e The loop is executed 10 times for i from 0 to 9 . Each time, i is added to y. So y = 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9, which 45 . The correct answer is E.
You might also like to view...
On Click begins the animation sequence immediately after the completion of the previous animation
Indicate whether the statement is true or false
At the beginning of this chapter we stated that volatile read?only memory was an oxymoron. However, there is one application where a volatile read?only memory might be very beneficial under certain conditions. Can you think what these applications might be?
What will be an ideal response?
If you want to share what a friend tweeted, giving him or her credit for the initial message, __________ it.
a. forward b. tweet c. retweet d. copy
To select an entire row, click the row heading.
Answer the following statement true (T) or false (F)