Angie A.

asked • 05/04/20

Need some help with method I was working on i need to return HighestColumn index of Jagged 2d array as a int

what I need to do

getHighestInColumnIndex

public static int getHighestInColumnIndex(double[][] data,

int col)

Returns index of the largest element of the selected column in the two dimensional array index 0 refers to the first column. If a

row in the two dimensional array doesn't have this column index, it is not an error, it doesn't participate in this method.

Parameters:

data - the two dimensional array

col - the column index to find the largest element of (0 refers to the first column)

Returns:

the index of the largest element of the column


my code:

public static int getHighestInColumnIndex(double[][] data, int col) {

double max = data[0][col];

int location = -1;

for(int i =0; i<data.length; i++) {

if(col>= 0 && col<data[i].length) 

if(data[i][col]>max) {

max = data[i][col];

location = i;

}


}


return location;


}


1 Expert Answer

By:

Patrick B. answered • 05/04/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.