-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
68 lines (57 loc) · 2.09 KB
/
calculator.java
File metadata and controls
68 lines (57 loc) · 2.09 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
import java.util.Scanner;
public class calculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("*********************************");
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
System.err.println("Please select the Operation Carefully!!\n" +
"1. For Addition\n" +
"2. For Subtraction\n" +
"3. For MultiplicationFor\n" +
"4. For Divide");
int input = sc.nextInt();
System.out.print("\n");
int output=0;
float div=0;
switch (input) {
case 1:
output = a + b;
System.out.println("Addition Result: "+output);
break;
case 2:
output = a - b;
System.out.println("Subtraction Result:"+output);
break;
case 3:
output = a * b;
System.out.println("Multiplication Result"+output);
break;
case 4:
if (b!=0) {
div =(float) a / b;
System.out.println("Division Result"+div);
} else {
System.out.println("Can't divide by 0");
}
break;
default:
System.out.println("Invalid Output");
break;
}
System.out.println("*********************************");
System.out.println("\nWant to Continue?\n"+
"1 for Yes\n"+
"2 for No");
int ex = sc.nextInt();
System.out.println();
if (ex==2) {
break;
}
}
sc.close();
}
}