-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_31_Example.java
More file actions
27 lines (25 loc) · 775 Bytes
/
_31_Example.java
File metadata and controls
27 lines (25 loc) · 775 Bytes
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
package chap_06;
class MathExample4 {
int add(int x, int y) { return x + y; }
long add(int x, long y) { return x + y; }
long add(long x, int y) { return x + y; }
long add(long x, long y) { return x + y; }
int add(int[] x) {
int result = 0;
for (int i = 0; i < x.length; i++) {
result += x[i];
}
return result;
}
}
public class _31_Example {
public static void main(String[] args) {
MathExample4 m = new MathExample4();
System.out.println(m.add(3, 3)); // 6
System.out.println(m.add(3, 3L)); // 6
System.out.println(m.add(3L, 3)); // 6
System.out.println(m.add(3L, 3L)); // 6
int[] x = {1, 2, 3, 4, 5};
System.out.println(m.add(x)); // 15
}
}