Skip to content

Commit e19edf4

Browse files
Calculator.java
1 parent 3ced69f commit e19edf4

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Calculator.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.*;
2+
3+
public class SimpleCalculator {
4+
public static void main(String[] args) {
5+
Scanner sc = new Scanner(System.in);
6+
7+
System.out.print("Enter first number: ");
8+
double a = sc.nextDouble();
9+
10+
System.out.print("Enter second number: ");
11+
double b = sc.nextDouble();
12+
13+
System.out.print("Enter operator (+ - * /): ");
14+
char op = sc.next().charAt(0);
15+
16+
double result = 0;
17+
18+
switch (op) {
19+
case '+': result = a + b; break;
20+
case '-': result = a - b; break;
21+
case '*': result = a * b; break;
22+
case '/': result = b != 0 ? a / b : 0; break;
23+
default: System.out.println("Invalid operator!");
24+
}
25+
26+
System.out.println("Result = " + result);
27+
}
28+
}

0 commit comments

Comments
 (0)