Write on the dashed lines the contents of the array after the indicated method e
ID: 3557123 • Letter: W
Question
Write on the dashed lines the contents of the array after the indicated method executes.
public static void arrayMystery(int[] a) {
for (int i = 1; i < a.length - 1; i++) {
if (a[i] > a[i + 1]) {
a[i] = a[i + 1] + a[i - 1];
}
}
}
int[] a1 = {42, 99, 42};
arrayMystery(a1); ___________________________
int[] a2 = {6, 8, 4, 2};
arrayMystery(a2); ___________________________
int[] a3 = {7, 7, 20, 8, 1};
arrayMystery(a3); ___________________________
int[] a4 = {4, 5, 3, 2, 1, 0};
arrayMystery(a4); ___________________________
Explanation / Answer
a1) 42 84 42
a2) 6 10 10 2
a3) 7 7 15 8 1
a4) 4 7 7 4 2 0
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.