-
Notifications
You must be signed in to change notification settings - Fork 1
/
Basic_Calculator.java
48 lines (33 loc) · 986 Bytes
/
Basic_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
//2019 Java Learning Repo
//Basic Calculator V1
//written by rwx777
import java.util.Scanner;
public class main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in); // Reading from System in
int number1;
int ScheiseNumber;
char operator;
int result = 0;
System.out.println("Enter the first Number: ");
number1 = reader.nextInt();
System.out.println("Enter an operator: ");
operator = reader.next().charAt(0);
System.out.println("Enter second Number: ");
ScheiseNumber = reader.nextInt();
if (operator == '+') {
result = number1 + ScheiseNumber;
} else if (operator == '-') {
result = number1 - ScheiseNumber;
} else if (operator == '/') {
result = number1 / ScheiseNumber;
} else if (operator == '*') {
result = number1 * ScheiseNumber;
} else {
System.out.println("Invalid Operator");
}
System.out.println("The result is: \n" + result);
reader.close();
// \n stands for newline
}
}