-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMainClass.java
More file actions
39 lines (31 loc) · 1.23 KB
/
Copy pathMainClass.java
File metadata and controls
39 lines (31 loc) · 1.23 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
package java_calculator;
import java.util.Scanner;
public class MainClass {
public void calculator() {
System.out.println(" Java Console Calculator");
Scanner scanner = new Scanner(System.in);
System.out.println("\n Please enter two to perform calculation");
System.out.print("\n First number: ");
int firstNumber = scanner.nextInt();
System.out.print("\n Second number: ");
int secondNumber = scanner.nextInt();
System.out.println("\n Select between (*,/,+,-)\n Type out the character in a single letter: ");
String operation = scanner.next();
switch (operation) {
case "*":
System.out.println("\n Your Result: "+ ( firstNumber * secondNumber ));
break;
case "/":
System.out.println("\n Your Result: "+ ( firstNumber / secondNumber ));
break;
case "+":
System.out.println("\n Your Result: "+ ( firstNumber + secondNumber ));
break;
case "-":
System.out.println("\n Your Result: "+ ( firstNumber - secondNumber ));
break;
default: System.out.println("\n Please select a valid character");
}
scanner.close();
}
}