-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
70 lines (68 loc) · 1.55 KB
/
Calculator.java
File metadata and controls
70 lines (68 loc) · 1.55 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
package placement;
import java.util.*;
public class Calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("<------Welcome to Calculator------>");
System.out.println("Enter 1 for addition");
System.out.println("Enter 2 for subtraction");
System.out.println("Enter 3 for multiplication");
System.out.println("Enter 4 for division");
System.out.println("Enter 5 to terminate");
int ch;
do
{
System.out.println("Enter your choice");
ch=sc.nextInt();
double a,b;
switch(ch)
{
case 1:
{
System.out.println("Addition");
System.out.println("Enter 2 numbers for addition");
a=sc.nextDouble();
b=sc.nextDouble();
System.out.println("Answer is " +(a+b));
break;
}
case 2:
{
System.out.println("Subtraction");
System.out.println("Enter 2 numbers for subtraction");
a=sc.nextDouble();
b=sc.nextDouble();
System.out.println("Answer is " +(a-b));
break;
}
case 3:
{
System.out.println("Multiplication");
System.out.println("Enter 2 numbers for multiplication");
a=sc.nextDouble();
b=sc.nextDouble();
System.out.println("Answer is " +(a*b));
break;
}
case 4:
{
System.out.println("Division");
System.out.println("Enter 2 numbers for division");
a=sc.nextDouble();
b=sc.nextDouble();
System.out.println("Answer is " +(a/b));
break;
}
case 5:
{
System.out.println("<----Terminating---->");
break;
}
default:
System.out.println("Wrong Choice");
break;
}
}
while(ch!=5);//when ch is 5 it will break the loop and terminate itself else it will keep on
}
}