-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasic_Calculator_wMethods.java
62 lines (45 loc) · 1.19 KB
/
Basic_Calculator_wMethods.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
//2019 Java Learning Repo
//Basic Calculator V2
//written by rwx777
import java.util.Scanner;
public class Calculator_wMethods {
public static Scanner reader = new Scanner(System.in);
public static int number1;
public static int number2;
public static char operator;
public static int result = 0;
public static void Addition() {
result = number1 + number2;
}
public static void Subtraction() {
result = number1 - number2;
}
public static void Division() {
result = number1 / number2;
}
public static void Multiply() {
result = number1 * number2;
}
public static void main(String[] args) {
System.out.println("Enter the First Number: ");
number1 = reader.nextInt();
System.out.println("Enter the operator");
operator = reader.next().charAt(0);
System.out.println("Enter second Number: ");
number2 = reader.nextInt();
if (operator == '+') {
Addition();
} else if (operator == '-') {
Subtraction();
} else if (operator == '/') {
Division();
} else if (operator == '*') {
Multiply();
} else {
System.out.println("Invalid Operator Dude !");
}
System.out.println("Your result is: ");
System.out.println(result);
reader.close();
}
}