File tree Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Expand file tree Collapse file tree 1 file changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ public class Calculator {
4+
5+ public static void main (String [] args ) {
6+
7+ Scanner input = new Scanner (System .in );
8+
9+ int ans = 0 ;
10+
11+ while (true ) {
12+
13+ System .out .print ("Enter a operator [+ - * / %] = " );
14+
15+ char op = input .next ().trim ().charAt (0 );
16+
17+ if (op == '+' || op == '-' || op == '*' || op == '/' || op == '%' ) {
18+
19+ System .out .print ("Enter one numbers : " );
20+
21+ int num1 = input .nextInt ();
22+
23+ System .out .print ("Enter two numbers : " );
24+
25+ int num2 = input .nextInt ();
26+
27+ if (op == '+' ) {
28+
29+ ans = num1 + num2 ;
30+
31+ }
32+
33+ if (op == '-' ) {
34+
35+ ans = num1 - num2 ;
36+
37+ }
38+
39+ if (op == '*' ) {
40+
41+ ans = num1 * num2 ;
42+
43+ }
44+
45+ if (op == '/' ) {
46+
47+ if (num2 != 0 ) {
48+
49+ ans = num1 / num2 ;
50+
51+ }
52+
53+ }
54+
55+ if (op == '%' ) {
56+
57+ ans = num1 % num2 ;
58+
59+ }
60+
61+ } else if (op == 'x' || op == 'X' ) {
62+
63+ break ;
64+
65+ }
66+
67+ System .out .println ("Result = " + ans );
68+
69+ }
70+
71+ }
72+
73+ }
You can’t perform that action at this time.
0 commit comments