-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathass16.java
More file actions
24 lines (20 loc) · 785 Bytes
/
Copy pathass16.java
File metadata and controls
24 lines (20 loc) · 785 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
//Write a method sum which may perform addition of integers and addition of floating-point numbers. Implement the scenario with method overloading.
// Class to demonstrate method overloading
public class Main {
// Method to add two integers
static int sum(int a, int b) {
return a + b;
}
// Method to add two floating-point numbers
static double sum(double a, double b) {
return a + b;
}
public static void main(String[] args) {
// Adding integers
int intSum = sum(5, 10);
System.out.println("Sum of integers: " + intSum);
// Adding floating-point numbers
double doubleSum = sum(3.5, 2.7);
System.out.println("Sum of floating-point numbers: " + doubleSum);
}
}