31 lines
696 B
Java
31 lines
696 B
Java
public class LargestOfThree {
|
|
|
|
public static <T extends Comparable<T>> T findLargest(T a, T b, T c) {
|
|
T max = a;
|
|
|
|
if (b.compareTo(max) > 0) {
|
|
max = b;
|
|
}
|
|
if (c.compareTo(max) > 0) {
|
|
max = c;
|
|
}
|
|
return max;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Integer a = 10;
|
|
Integer b = 5;
|
|
Integer c = 15;
|
|
|
|
System.out.println("The largest number is: " + findLargest(a, b, c));
|
|
|
|
String str1 = "apple";
|
|
String str2 = "orange";
|
|
String str3 = "banana";
|
|
|
|
System.out.println(
|
|
"The largest string is: " + findLargest(str1, str2, str3)
|
|
);
|
|
}
|
|
}
|