Files
AdvanceJava/methodp1.java

16 lines
516 B
Java

// 8C
public class methodp1{
public static <T extends Comparable<T>> T findMax(T x, T y){
return x.compareTo(y) > 0 ? x : y;
}
public static void main(String[] args){
Integer maxInt = findMax(5, 10);
System.out.println("Maximum of 5 and 10 is: " + maxInt);
Double maxDouble = findMax(3.5, 7.8);
System.out.println("Maximum of 3.5 and 7.8 is: " + maxDouble);
String maxString = findMax("apple", "banana");
System.out.println("Maximum of apple and banana is: " + maxString);
}
}