-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySwitchCalculator.java
More file actions
47 lines (40 loc) · 1.52 KB
/
MySwitchCalculator.java
File metadata and controls
47 lines (40 loc) · 1.52 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
/*
This program's purpose is to function as a basic calculator, implementing elementary functions, while showing off
use of switch statements.
Written by John Orekunrin
Created on 10/02/2018 @ 09:30 PM
*/
import java.util.Scanner;
public class MySwitchCalculator{
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
int num1, num2;
String operation;
System.out.println("Enter an integer: ");
num1 = keyboard.nextInt();
System.out.println("Enter another integer: ");
num2 = keyboard.nextInt();
System.out.println("Choose an operation");
operation = keyboard.next();
switch(operation){
case "+":
System.out.println("Add: " + num1 + " plus " + num2 + " equals " + (num1 + num2));
break;
case "-":
System.out.println("Subtract: " + num1 + " minus " + num2 + " equals " + (num1 - num2));
break;
case "*":
System.out.println("Multiply: " + num1 + " times " + num2 + " equals " + (num1 * num2));
break;
case "/":
System.out.println("Divide: " + num1 + " divided by " + num2 + " equals " + (num1 / num2));
break;
case "%":
System.out.println("Modulo (The remainder of): " + num1 + " and " + num2 + " is " + (num1 % num2));
break;
default:
System.out.println("Enter a valid operation");
break;
}
}
}