-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCalculator.java
More file actions
57 lines (43 loc) · 1.45 KB
/
Calculator.java
File metadata and controls
57 lines (43 loc) · 1.45 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
import java.io.*;
public class Calculator {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter First number");
double num1 = Double.parseDouble(reader.readLine());
System.out.println("Enter second nuber");
double num2 = Double.parseDouble(reader.readLine());
System.out.println(
"Enter + for Addition \n" + "- for Subraction\n" + "* for Multiplication\n" + "/ for Division");
String input = reader.readLine();
char operation = input.charAt(0);
Condition(num1, num2, operation);
}
private static void Condition(double num1, double num2, char operation) {
switch (operation) {
case '+':
System.out.println("The sum of " + num1 + " and " + num2 + " is " + DoAddition(num1, num2));
break;
case '-':
System.out.println("The sum of " + num1 + " and " + num2 + " is " + DoSubract(num1, num2));
break;
case '*':
System.out.println("The sum of " + num1 + " and " + num2 + " is " + DoMultiply(num1, num2));
break;
case '/':
System.out.println("The sum of " + num1 + " and " + num2 + " is " + DoDivision(num1, num2));
break;
}
}
static double DoDivision(double a, double b) {
return a / b;
}
static double DoMultiply(double a, double b) {
return a * b;
}
static double DoAddition(double a, double b) {
return a + b;
}
static double DoSubract(double a, double b) {
return a - b;
}
}