- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassOverloading.java
More file actions
Latest commit
43 lines (32 loc) · 964 Bytes
/
Copy pathclassOverloading.java
File metadata and controls
43 lines (32 loc) · 964 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
32
33
34
35
36
37
38
39
40
41
42
43
importjava.util.*;
publicclassclassOverloading {
publicvoidsum(intarr[], intsize){
intsum = 0;
for(inti = 0;i<size;i++){
sum += arr[i];
}
System.out.println("Sum of Integer arr : " + sum);
}
publicvoidsum(floatarr[], intsize){
floatsum = 0;
for(inti = 0;i<size;i++){
sum+=arr[i];
}
System.out.printf("Sum of float arr : %.1f\n", sum);
}
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
intn = sc.nextInt();
intintArr[] = newint[n];
floatfloatArr[] = newfloat[n];
for (inti = 0; i < n; i++) {
intArr[i] = sc.nextInt();
}
for (inti = 0; i < n; i++) {
floatArr[i] = sc.nextFloat();
}
classOverloadingobj = newclassOverloading();
obj.sum(intArr, n);
obj.sum(floatArr, n);
}
}