-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocation.java
More file actions
38 lines (34 loc) · 1.24 KB
/
Copy pathLocation.java
File metadata and controls
38 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class Location {
public int row;
public int column;
public double maxValue;
public static Location locateLargest(double[][] a) {
Location forReturn = new Location();
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
if (a[i][j] > forReturn.maxValue) {
forReturn.maxValue = a[i][j];
forReturn.row = i;
forReturn.column = j;
}
}
}
return forReturn;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of row and collumn of array: ");
int row = sc.nextInt();
int column = sc.nextInt();
double size[][] = new double[row][column];
System.out.print("Enter the array: ");
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
size[i][j] = sc.nextDouble();
}
}
Location display = Location.locateLargest(size);
System.out.println("The location of largest element is " + display.maxValue + " at (" + display.row + "," + display.column + ")");
}
}