-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
65 lines (52 loc) · 2 KB
/
calculator.java
File metadata and controls
65 lines (52 loc) · 2 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
package java_calculator;
import java.util.Scanner;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
class calculator {
public static void main(String[] args) throws IOException, URISyntaxException {
try {
//variables
double num1;
double num2;
String operator;
// input
Scanner input = new Scanner(System.in);
System.out.println("enter the first digit:");
num1 = input.nextDouble();
System.out.println("enter the mathematical operator:");
operator = input.next();
System.out.println("enter the second digit:");
num2 = input.nextDouble();
//operation
if (operator.equals("+")) {
System.out.println("the result is: " + (num1 + num2));
} else if (operator.equals("-")) {
System.out.println("the result is: " + (num1 - num2));
} else if (operator.equals("*")) {
System.out.println("the result is: " + (num1 * num2));
} else if (operator.equals("/")) {
if (num2 == 0) {
System.out.println("you can't devide by zero :(");
}
else {
System.out.println("the result is: " + (num1 / num2));
}
} else if (operator.equals("%")) {
int value1 = (int) num1;
int value2 = (int) num2;
System.out.println("the result is: " + (value1 % value2));
}
else {
Desktop.getDesktop().browse(new URI("i think you made a critacal error with the operator"));
}
//thank you message
System.out.println("thanks for running my code");
} catch (Exception e) {
System.out.println("hmm something went wrong ...");
System.exit(0);
}
}
}
//created by ebayboy123