Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following method. For each multi-dimensional array listed below, write the final array state that would result if the given array were passed as
Consider the following method. For each multi-dimensional array listed below, write the final array state that would result if the given array were passed as a parameter to the method.
public void array2dMystery4(int[][] a) {
for (int r = 1; r < a.length - 1; r++) {
for (int c = 1; c < a[0].length - 1; c++) {
int sum1 = a[r - 1][c - 1] + a[r + 1][c + 1];
int sum2 = a[r - 1][c + 1] + a[r + 1][c - 1];
if (sum1 > sum2) {
a[r][c] = sum1;
} else {
a[r][c] = sum2;
}
}
}
}
The 2 arrays needed:
int[][] a1 = { {3, 4, 5, 6, 2}, {4, 2, 6, 1, 3}, {5, 7, 4, 9, 1}, {1, 6, 7, 2, 8} }; | |
int[][] a2 = { {0, 1, 0, 1, 0, 1}, {2, 1, 2, 1, 2, 1}, {0, 5, 0, 5, 0, 5}, {3, 2, 3, 2, 3, 2}, {1, 4, 1, 4, 1, 4} }; |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started