-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.java
More file actions
73 lines (37 loc) · 1.22 KB
/
calculator.java
File metadata and controls
73 lines (37 loc) · 1.22 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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//program to implement a command line calculator
import java.util.Scanner;
class calculator
{
public static void main(String a[])
{
int n,x,y,s;
System.out.println("Enter your choice number: \n 1. Add\n 2. Subtract\n 3. Multiply\n 4. Divide\n 5. Mod\n");
n=Integer.parseInt(a[0]);
x=Integer.parseInt(a[1]);
y=Integer.parseInt(a[2]);
switch(n)
{
case 1:
s=x+y;
System.out.println("sum of " + x + " and " + y +" is " +s);
break;
case 2:
s=x-y;
System.out.println("subtraction of " + x + " and " + y +" is " +s);
break;
case 3:
s=x*y;
System.out.println("multiplication of " + x + " and " + y +" is " +s);
break;
case 4:
s=x/y;
System.out.println("division of " + x + " and " + y +" is " +s);
break;
case 5:
s=x%y;
System.out.println("mod of " + x + " and " + y +" is " +s);
break;
default: break;
}
}
}