-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassOverloading.java
More file actions
43 lines (32 loc) · 964 Bytes
/
classOverloading.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
import java.util.*;
public class classOverloading {
public void sum(int arr[], int size){
int sum = 0;
for(int i = 0;i<size;i++){
sum += arr[i];
}
System.out.println("Sum of Integer arr : " + sum);
}
public void sum(float arr[], int size){
float sum = 0;
for(int i = 0;i<size;i++){
sum+=arr[i];
}
System.out.printf("Sum of float arr : %.1f\n", sum);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int intArr[] = new int[n];
float floatArr[] = new float[n];
for (int i = 0; i < n; i++) {
intArr[i] = sc.nextInt();
}
for (int i = 0; i < n; i++) {
floatArr[i] = sc.nextFloat();
}
classOverloading obj = new classOverloading();
obj.sum(intArr, n);
obj.sum(floatArr, n);
}
}