I have an assignment that I dont know where to begin. If someone could guide me along I would much appreciate it! Thanks alot.
Write a method
public static int[] avgRows(int[][] a) {}
This method takes a 2-dimensional array as input and returns an array containing the averages of each row of the 2-d array. For example, for input
{{1, 2, 3}, {3, 4, 5}}
your program should output
{2, 4}
(beacuse (1+2+3)/3=2, (3+4+5)/3=4).
Write a main method to construct an example 2d array, pass it as an argument to your avgRows method, and print the resulting array.
This, unfortunately, is what I have so far:
public class Avgtwod {
public static int[][] avgRows(int[][] a) {
int[][] avgRows = {{1, 2, 3}, {3, 4, 5}};
int total = 0;
for (int row = 0; row < avgRows.length; row++) {
total += avgRows;
}
return avgRows;
}
}