public class Location {
public int row
;
public int column
;
public double maxValue
;
}
import java
.util
.Scanner
;
public class Test {
public static void main(String
[] args
) {
System
.out
.print("Enter the number of rows and columns in the array ");
Scanner input
= new Scanner(System
.in
);
int row
= input
.nextInt();
int column
= input
.nextInt();
double[][] a
= new double[row
][column
];
System
.out
.println("Enter the array:");
for (int i
= 0; i
< a
.length
; i
++) {
for (int j
= 0; j
< a
[i
].length
; j
++) {
a
[i
][j
] = input
.nextDouble();
}
}
input
.close();
System
.out
.println("The location of the largest element is " + locateLargest(a
).maxValue
+ " at " +
(locateLargest(a
).row
+ "," + locateLargest(a
).column
));
}
public static Location
locateLargest(double[][] a
) {
Location location
= new Location();
for (int i
= 0; i
< a
.length
; i
++) {
for (int j
= 0; j
< a
[i
].length
; j
++) {
if (location
.maxValue
< a
[i
][j
]){
location
.maxValue
= a
[i
][j
];
location
.row
= i
;
location
.column
= j
;
}
}
}
return location
;
}
}
"D:\java 12.0\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\lib\idea_rt.jar=60321:C:\Program Files\JetBrains\IntelliJ IDEA 2019.2\bin" -Dfile
.encoding
=UTF
-8 -classpath C
:\Users\
26601\Desktop\library_management_sys
-master\untitled4\out\production\untitled4 Test
Enter the number of rows and columns in the array
3 4
Enter the array
:
23.5 35 2 10 4.5 3 45 3.5 35 44 5.5 9.6
The location of the largest element is
45.0 at
1,2
Process finished with exit code
0