-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathCalculator.java
51 lines (40 loc) · 1.47 KB
/
Calculator.java
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
/*
Make a Calculator.
Take 2 numbers(a&b)from the user and an operation as follows:
1:+(Addition)a+b.
2:-(Subtraction)a-b.
3:*(Multiplication)a*b.
4:/(Division)a/b.
5:%(Moduloorremainder)a%b.
Calculate the result according to the operation given and display it to the user.
*/
package chapter3sol;
import java.util.*;
public class s1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter First Number: ");
double a = sc.nextDouble();
System.out.println("Enter Second Number: ");
double b = sc.nextDouble();
System.out.print("choose one: \n 1. For Addition\n 2. For Substraction\n 3. For Multiplication\n 4. For Division\n 5. For Modulation \n : ");
int n = sc.nextInt();
switch (n) {
case 1:
System.out.println("Addition: "+(a+b));
break;
case 2:
System.out.println("Substraction: "+(a-b));
break;
case 3:
System.out.println("Multiplication: "+(a*b));
break;
case 4:
System.out.println("Division: "+(a/b));
break;
default:
System.out.println("Plz Choose Right Option");
break;
}
}
}