forked from waboke/calculator_app_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
32 lines (29 loc) · 1.19 KB
/
Copy pathCalculator.java
File metadata and controls
32 lines (29 loc) · 1.19 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
import java.util.Scanner;
public class Calculator{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("*********************Calculator**************************");
System.out.print("Enter the first number: ");
double num1 = sc.nextDouble();
System.out.print("Enter the second number: ");
double num2 = sc.nextDouble();
System.out.println("Enter: ");
System.out.println("1 for Addition");
System.out.println("2 for Subtraction");
System.out.println("3 for division");
System.out.println("4 for multiplication");
System.out.print(">>>");
double operator = sc.nextDouble();
if (operator == 1){
System.out.println("Result "+ (num1+num2));
}else if (operator == 2) {
System.out.println("Result "+ (num1-num2));
}else if(operator == 3 && num2 != 0){
System.out.println("Result "+ (num1/num2));
}else if(operator == 4){
System.out.println("Result "+ (num1*num2));
}else if(num2 == 0){
System.out.println("Error! Division by zero is not allowed");
}
}
}