Question
Implement two static methods that can take a generic type array as an argument. LAB ACTIVITY 11.4.1: zyLab 11 Generics 0/6 Generics.java Load default template... 1 public class Genericst 2 public static void main (String[] args) Integer[] ?ntArray {5, 3, 108, 27, 81, 4, 35); Double[] doubleArray-11.28, 5.3, 7.9, 0.5, 0.3, 2.8; Character[] charArray {'H', 'E', 'L', 'L', '0'); 4 System.out.println(maxElement(intArray)); System.out.println(maxElement(doubleArray)) System.out.println(maxElement(charArray)) System.out.println(); 12 13 System.out.println(minElement(intArray)); System.out.println(minElement (doubleArray)); System.out.println(minElement(charArray)) System.out.println(); 15 16 17 18 19 20 21 printArray (intArray); System.out.println); printArray(doubleArray); System.out.println); printArray (charArray) System.out.println(); 23 26 27 *FIXME (1) Implement static method maxElement) which takes a T] array as argument, and returns the maximum element in the array Note that T extends Comparable 29 30 31 32 FIXME (2) Implement static method minElement) which takes a T] array as argument, and returns the minimum element in the array Note that T extends Comparable/ 34 35 36 37 public array){ static í Comparable> void printArray(T[] {
Explanation / Answer
public class Generics { public static T maxElement(T[] arr) { T max = arr[0]; for(int i = 0; i 0) { max = arr[i]; } } return max; } public static T minElement(T[] arr) { T min = arr[0]; for(int i = 0; i