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.

Computer Science & Information Technology

You might also like to view...

A dot leader is the most commonly used type of leader, with a dot as the leader ________

A) character B) point C) trail D) path

Computer Science & Information Technology

Many businesses have realized that social media is not an important part of their marketing plan

Indicate whether the statement is true or false

Computer Science & Information Technology