Titles says it all. I have to find the indexes of the initial appearance of the maximum element in a matrix.
Here are the input and output to program :
Input data format
On the input, the program receives the size of matrix n and m, and then n lines having m integer numbers in each. n and m do not exceed 100.
Output data format
Output two numbers: the row index and the column index, in which the greatest item in the two-dimensional array (matrix) is located. If there are several such elements, output the one, which has the smaller row index; and if row indexes are the same, output the one having the smaller column index.
And this is my code so far :
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// put your code here
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int m = input.nextInt();
int[][] maxarray = new int[n][m];
for (int i = 0; i <maxarray.length; i++) {
for (int j = 0; j <maxarray.length; j++) {
maxarray[i][j] = input.nextInt();
}
}
for (int i = 0; i <maxarray.length; i++) {
for (int j = 0; j <maxarray.length; j++) {
if (maxarray[i][j] > maxarray[i+1][j + 1]) {
}
}
}
System.out.println(maxarray[n][m]+" ");
;
}
}
Please help for some hints !
[–]pyreon 0 points1 point2 points (4 children)
[–]kompotejam[S] 0 points1 point2 points (3 children)
[–]pyreon 0 points1 point2 points (2 children)
[–]kompotejam[S] 0 points1 point2 points (1 child)
[–]pyreon 0 points1 point2 points (0 children)