forked from PrajaktaSathe/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
84 lines (52 loc) · 2.01 KB
/
Calculator.java
File metadata and controls
84 lines (52 loc) · 2.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
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();
// if (n==1) {
// System.out.println("Addition: "+a+b);
// }else if(n==2) {
// System.out.println("Substraction: "+ (a-b));
// }else if(n==3){
// System.out.println("Multiplication: "+a*b);
// }else if(n==4){
// System.out.println("Division: "+a/b);
// }else if(n==5){
// System.out.println("Modulation: "+a%b);
// } else
// System.out.println(" Plz Choose Right Option");
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;
}
}
}