-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator.java
42 lines (36 loc) · 1.21 KB
/
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
import java.util.Scanner;
/**
* This program is a simple calculator that performs 4 operations
* @author Riya Kore
*/
public class Calculator {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
System.out.print("You have to input two numbers and the program will ");
System.out.println("output the answer based on the operation you choose.");
double num1;
double num2;
char operationIs;
double answerIs = 0.0;
System.out.println("Enter first number: ");
num1 = scnr.nextDouble();
System.out.println("Enter second number: ");
num2 = scnr.nextDouble();
System.out.println("Enter operation: ");
System.out.println("Choose from + , - , * , /");
operationIs = scnr.next().charAt(0);
if (operationIs == '+'){
answerIs = num1 + num2;
}
else if (operationIs == '-') {
answerIs = num1 - num2;
}
else if (operationIs == '*') {
answerIs = num1 * num2;
}
else if (operationIs == '/') {
answerIs = num1 / num2;
}
System.out.print("Your answer is: " + answerIs);
}
}