-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
44 lines (36 loc) · 753 Bytes
/
Copy pathCalculator.java
File metadata and controls
44 lines (36 loc) · 753 Bytes
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
package oracle.src.DSA;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args){
double result= 0;
System.out.println("Enter First Number");
Scanner sc = new Scanner(System.in);
double a = sc.nextDouble();
System.out.println("Enter Valid Operator + - * /");
String operator = sc.next();
if(operator.matches("[+\\-*/]")){
System.out.println("Please Enter Second Number ");
double b = sc.nextDouble();
switch (operator){
case ("+") :
result =(a+b);
break;
case ("-") :
result = (a-b);
break;
case ("*"):
result = (a*b);
break;
case ("/") :
if(b != 0){
result = (a/b);
}else{
System.out.println("Enter A Valid Number");
}
break;
default:
break;
}
System.out.println("Result " +result);
}
}}