public class Maximum { public int max1D(int [] list){ // finds the max in a single row return max1DHelper(list, 0); // needs a helper } public int max1DHelper(int [] list, int start){ // helper function, recursively goes through elements in a row if (start == list.length - 1) { return list[start]; } else { return Math.max(list[start], max1DHelper(list, start + 1)); } } public int max2D(int[][] table) { // returns the max in a 2D array return max2DHelper(table, 0); // needs a recursive helper } public int max2DHelper(int[][] table, int startRow) { // helper goes row by row if(startRow == table.length - 1) { // this is the last row in the table return max1D(table[startRow]); } else { // as long as there are rows left // get the max of the max of the current row and the max of the remaining rows return Math.max(max1D(table[startRow]), max2DHelper(table, startRow+1)); } } public static void main(String[] args) { Maximum rec = new Maximum(); int [][] table = {{ 1, 5, 2, 3},{4, 2, 6, 8}, {-1, 2, 5, 2}}; System.out.println("maximum in the list: " + rec.max2D(table)); } }