Upload files to "OOP/Java/Lab/Week12"
This commit is contained in:
parent
2ae5d58f75
commit
100e80ccc3
5 changed files with 226 additions and 0 deletions
30
OOP/Java/Lab/Week12/LargestOfThree.java
Normal file
30
OOP/Java/Lab/Week12/LargestOfThree.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
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)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue