forked from AndrewProgramming/JavaTutorialCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMethodOverloading.java
More file actions
53 lines (44 loc) · 1.1 KB
/
TestMethodOverloading.java
File metadata and controls
53 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package method;
public class TestMethodOverloading {
/**
* Main method
*/
public static void main(String[] args) {
// Invoke the max method with int parameters
System.out.println("The maximum of 3 and 4 is "
+ max(3, 4));
// Invoke the max method with the double parameters
System.out.println("The maximum of 3.0 and 5.4 is "
+ max(3.0, 5.4));
// Invoke the max method with three double parameters
System.out.println("The maximum of 3.0, 5.4, and 10.14 is "
+ max(3.0, 5.4, 10.14));
System.out.println(max(2, 2.5));
}
/**
* Return the max of two int values
*/
public static int max(int num1, int num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}
/**
* Find the max of two double values
*/
public static double max(double num1, double num2) {
if (num1 > num2) {
return num1;
} else {
return num2;
}
}
/**
* Return the max of three double values
*/
public static double max(double num1, double num2, double num3) {
return max(max(num1, num2), num3);
}
}