-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathCalculator.java
More file actions
57 lines (38 loc) · 953 Bytes
/
Calculator.java
File metadata and controls
57 lines (38 loc) · 953 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package assignment;
import java.util.Scanner;
public class Calculator {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("enter first number");
int a=sc.nextInt();
System.out.println("enter enter operation");
char c=sc.next().charAt(0);
System.out.println("enter second number");
int b=sc.nextInt();
opr(a,c,b);
}
public static void opr(double a,char b,double c) {
double ans;
switch (b) {
case '+':
ans=a+c;
System.out.println(ans);
break;
case '-':
ans=a-c;
System.out.println(ans);
break;
case '/':
ans=a/c;
System.out.println(ans);
break;
case '*':
ans=a*c;
System.out.println(ans);
break;
default:
System.out.println("please enter a valid operator");
}
}
}