-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.java
116 lines (113 loc) · 5.69 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.lang.Math;
import java.io.*;
public class calculator {
public static void main(String[] args) throws IOException, InterruptedException {
String c, n, x;
double a, b, add, div, sub, mul, fct=1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("\n Scientific Calculator \n Enter your choice to perform an action: \n" );
System.out.println("Enter 1 for Addition(+) \n 2 for Subtraction(-) \n 3 for Multiplication(x) \n 4 for Division(÷) \n 5 for Sin \n 6 for Cos \n 7 for Tan\n 8 for Power(^)\n 9 for Pi(π) \n 10 for RootOver(√) \n 11 for Factorial(x!) \n 0 for Exit \n=> ");
x = br.readLine();
int s = Integer.parseInt(x);
switch (s) {
case 1 -> {
System.out.println("\n Enter 1st number: "); //Made with love by Debanjan Mukherjee :D
c = br.readLine();
a = Double.parseDouble(c);
System.out.println(" Enter 2nd number: ");
n = br.readLine();
b = Double.parseDouble(n);
add = a + b;
System.out.println("The addition of the numbers: " + a + "+" + b + " = " + add);
}
case 2 -> {
System.out.println("\n Enter 1st number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println(" Enter 2nd number: ");
n = br.readLine();
b = Double.parseDouble(n);
sub = a - b;
System.out.println("The Subtraction of the numbers: " + a + "-" + b + " = " + sub);
}
case 3 -> {
System.out.println("\n Enter 1st number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println(" Enter 2nd number: ");
n = br.readLine();
b = Double.parseDouble(n);
mul = a * b;
System.out.println("The Subtraction of the numbers: " + a + "x" + b + " = " + mul);
}
case 4 -> {
System.out.println("\n Enter 1st number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println(" Enter 2nd number: ");
n = br.readLine();
b = Double.parseDouble(n);
div = a / b;
System.out.println("The Subtraction of the numbers: " + a + "÷" + b + " = " + div); //Made with love by Debanjan Mukherjee :D
}
case 5 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println("Sin("+a+")= "+Math.sin(a));
}
case 6 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println("Cos("+a+")= "+Math.cos(a));
}
case 7 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println("Tan("+a+") = "+Math.tan(a));
}
case 8 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println("Enter ^ :"); //Made with love by Debanjan Mukherjee :D
n = br.readLine();
b=Double.parseDouble(n);
System.out.println(a+"^"+b+"= "+Math.pow(a, b));
}
case 9 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
b= a*3.141592653589793238462643383279502884197;
System.out.println(a+"π = "+b);
}
case 10 ->{
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
System.out.println(" √"+a+" = "+Math.pow(a, 0.5));
}
case 11 -> {
System.out.println("\n Enter the number: ");
c = br.readLine();
a = Double.parseDouble(c);
for(int i=1;i<=a;i++){
fct=fct*i;
}
System.out.println(a+"! = "+fct);
}
case 0 -> {
System.out.println("\n Exiting Program...");
System.exit(0);
}
default -> System.out.println("Enter valid choice!");
}
Thread.sleep(2000);
}
}
}
//Made with love by Debanjan Mukherjee :D