Answer:
Step-by-step explanation:
Here is the main method to return the largest element in the array:-
public class ArrayUtils {
public static int[] locateLargest(int[][] A) {
int max = A[0][0];
int maxRow = 0;
int maxCol = 0;
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < A[i].length; j++) {
if (A[i][j] > max) {
max = A[i][j];
maxRow = i;
maxCol = j;
}
}
}
int[] location = {maxRow, maxCol};
return location;
}
public static void main(String[] args) {
int[][] array = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[] largestLocation = locateLargest(array);
int maxRow = largestLocation[0];
int maxCol = largestLocation[1];
System.out.println("The largest element is located at row " + maxRow + ", column " + maxCol);
}
}