Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What i

ID: 3556132 • Letter: C

Question

Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What is the value of total after the following loops complete?

a.?int total = 0; for (int i = 0; i < 10; i++) { total = total + a[i]; }

b.?int total = 0; for (int i = 0; i < 10; i = i + 2) { total = total + a[i]; }

c.?int total = 0; for (int i = 1; i < 10; i = i + 2) { total = total + a[i]; }

d.?int total = 0; for (int i = 2; i <= 10; i++) { total = total + a[i]; } e.?int total = 0; for (int i = 1; i < 10; i = 2 * i) { total = total + a[i]; } f.?int total = 0; for (int i = 9; i >= 0; i--) { total = total + a[i]; } g.?int total = 0; for (int i = 9; i >= 0; i = i - 2) { total = total + a[i]; } h.?int total = 0; for (int i = 0; i < 10; i++) { total = a[i] - total; } ?

Consider the following array: int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 }; What are the contents of the array a after the following loops complete?

a.?for (int i = 1; i < 10; i++) { a[i] = a[i - 1]; }

b.?for (int i = 9; i > 0; i--) { a[i] = a[i - 1]; }

c.?for (int i = 0; i < 9; i++) { a[i] = a[i + 1]; }

d.?for (int i = 8; i >= 0; i--) { a[i] = a[i + 1]; }

e.?for (int i = 1; i < 10; i++) { a[i] = a[i] + a[i - 1]; }

f.?for (int i = 1; i < 10; i = i + 2) { a[i] = 0; }

g.?for (int i = 0; i < 5; i++) { a[i + 5] = a[i]; }

h.?for (int i = 1; i < 5; i++) { a[i] = a[9 - i]; }

Explanation / Answer

a) 25
b) 13
c) 12
d) ArrayIndexOutOfBoundsException
e) 11
f) 25
g) 12
h) -1

a) 1 1 1 1 1 1 1 1 1 1
b) 1 1 2 3 4 5 4 3 2 1
c) 2 3 4 5 4 3 2 1 0 0
d) 0 0 0 0 0 0 0 0 0 0
e) 1 3 6 10 15 19 22 24 25 25
f) 1 0 3 0 5 0 3 0 1 0
g) 1 2 3 4 5 1 2 3 4 5
h) 1 1 2 3 4 4 3 2 1 0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote