-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_sub.java
More file actions
40 lines (32 loc) · 1.01 KB
/
add_sub.java
File metadata and controls
40 lines (32 loc) · 1.01 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
//Program to calculate the numbers
import java.util.Scanner;
public class add_sub {
// methods for addition
static public void add(int a, int b) {
int ans = a + b;
System.out.println("The addition of two number is : " + ans);
}
// subtraction with return type
static int sub(int a, int b) {
return a - b;
}
// Multiplication of two number
static int mul(int a, int b) {
return a * b;
}
// division
static float div(float a, float b) {
return a / b;
}
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the first value: ");
int x = obj.nextInt();
System.out.println("Enter the second value: ");
int y = obj.nextInt();
add(x, y);
System.out.println("The subtraction is : " + sub(x, y));
System.out.println("The multiplication is : " + mul(x, y));
System.out.println(("The division is : " + div(x, y)));
}
}