-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathCalulator.java
70 lines (43 loc) · 1.5 KB
/
Calulator.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
import java.util.Scanner;
public class Calulator{
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
double num1, num2 , num3;
// Take input from the user
// Scanner sc = new Scanner(System.in);
System.out.println("Enter the numbers");
// take the inputs
num1 = sc.nextDouble();
num2 = sc.nextDouble();
num3 = sc.nextDouble();
System.out.println("Enter the operator (+,-,*,/)");
char op = sc.next().charAt(0);
double o = 0;
switch (op) {
// case to add three numbers
case '+':
o = num1 + num2 + num3;
break;
// case to subtract three numbers
case '-':
o = num1 - num2 - num3;
break;
// case to multiply three numbers
case '*':
o = num1 * num2 * num3;
break;
// case to divide three numbers
case '/':
o = num1 / num2 / num3;
break;
default:
System.out.println("You enter wrong input");
break;
}
// System.out.println("The final result:");
// System.out.println();
// print the final result
System.out.println(num1 + " " + op + " " + num2
+ " " + op + " " + num3 + " " + op + " = " + o);
}
}