-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverloading.java
More file actions
31 lines (26 loc) · 784 Bytes
/
Overloading.java
File metadata and controls
31 lines (26 loc) · 784 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
28
29
30
31
public class Overloading {
public static int sumof(int arr[]) {
int sum = 0;
for(int i = 0; i < arr.length; i++){
if (arr[i] % 2 != 0) {
sum = sum + arr[i];
}
}
return sum;
}
public static long sumof(long arr[]) {
long sum = 0;
for(int i = 0; i < arr.length; i++){
if (arr[i] % 2 == 0) {
sum = sum + arr[i];
}
}
return sum;
}
public static void main(String[] args) {
int arr[] = {2,4,6,3,2,4,5,6,54,43,32,2,75,23};
long ar[] = {2,4,6,3,2,4,5,6,54,43,32,2,75,23};
System.out.println(sumof(arr));
System.out.println(sumof(ar));
}
}