-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calc.java
37 lines (30 loc) · 1.02 KB
/
Calc.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
import java.util.*;
public class Calc
{
public static void main(String [] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Welcome to this simple calculator, you will be asked to enter two digits.");
System.out.print("Enter your first number: ");
int num1 = in.nextInt();
System.out.print("Enter your second number: ");
int num2 = in.nextInt();
System.out.print("What operator would you like to use? (+, -, %, /, *): ");
char oper = in.next().charAt(0);
int answer = 0;
switch (oper)
{
case '+': answer = num1 + num2;
break;
case '-': answer = num1 - num2;
break;
case '%': answer = num1 % num2;
break;
case '/': answer = num1 / num2;
break;
case '*': answer = num1 * num2;
break;
}
System.out.println("Your answer is: " + answer);
}
}