C:\Users\ar114\Documents\NetBeansProjects\Exam1_CalebFontenot\src\main\java\com\calebfontenot\exam1_calebfontenot\Location.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package com.calebfontenot.exam1_calebfontenot;
@author
public class Location {
public static int row;
public static int column;
public static double maxValue;
int x, y;
Location(int x, int y) {
this.x = x;
this.y = y;
}
public static Location locateLargest(double[][] arr) {
maxValue = arr[0][0];
for (int i = 0; i < arr.length - 1; ++i) {
for (int j = 0; j < arr[i].length; ++j) {
if (maxValue < arr[i][j]) {
maxValue = arr[i][j];
column = i;
row = j;
}
}
}
return new Location(column, row);
}
@Override
public String toString() {
String s = "The location of the largest element is ";
s += maxValue + " at (" + this.x + ", "+ this.y +")";
return s;
}
public static void main(String[] args) {
double[][] arr = {
{23.5, 35, 2, 10, 12},
{4.5, 3, 45},
{35, 44, 5.5, 9.6}
};
System.out.println(locateLargest(arr));
}
}