Q:

(Maximum element in a two-dimensional array) Write a generic method that returns the maximum element in a two-dimensional array

0

(Maximum element in a two-dimensional array) Write a generic method that returns the maximum element in a two-dimensional array.

public static < E  extends comparable<E>> E max(E[] [] list) 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

/*********************************************************************************
* (Maximum element in a two-dimensional array) Write a generic method that       *
* returns the maximum element in a two-dimensional array.                        *
*                                                                                *
* public static <E extends Comparable<E>> E max(E[][] list)                      *
*********************************************************************************/
public class Exercise_19_06 {
	/** Method returns the maximum element in a two-dimensional array */
	public static <E extends Comparable<E>> E max(E[][] list) {
		E max = list[0][0];
		for (int i = 0; i < list.length; i++) {
			for (int j = 0; j < list[i].length; j++) {
				if (list[i][j].compareTo(max) > 0)
					max = list[i][j];
			}
		}
		return max;
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now