-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOverload.java
More file actions
60 lines (44 loc) · 1.23 KB
/
Overload.java
File metadata and controls
60 lines (44 loc) · 1.23 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
54
55
56
57
58
59
60
//4:Write functions for making addition of different types
//(use FunctionOverloading);
import java.util.Scanner;
public class Overload {
public static void add() {
System.out.println("Adding");
}
public static void add(int num1, int num2) {
System.out.println("sum :"+(num1+num2));
}
public static void add(float num1, float num2) {
System.out.println("sum :"+(num1+num2));
}
public static void add(double num1, double num2) {
System.out.println("sum :"+(num1+num2));
}
public static void add(int num1, float num2,double num3) {
System.out.println("sum :"+(num1+num2+num3));
}
public static void main(String[] args) {
int num1,num2;
float num3,num4;
double num5,num6;
Scanner input = new Scanner(System.in);
System.out.print("Enter Num1 : ");
num1=input.nextInt();
System.out.print("Enter Num2 : ");
num2=input.nextInt();
System.out.print("Enter Num3 : ");
num3=input.nextFloat();
System.out.print("Enter Num4 : ");
num4=input.nextFloat();
System.out.print("Enter Num5 : ");
num5=input.nextDouble();
System.out.print("Enter Num6 : ");
num6=input.nextDouble();
add();
add(num1,num2);
add(num3,num4);
add(num5,num6);
add(num1,num3,num5);
input.close();
}
}