-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCal.java
More file actions
49 lines (45 loc) · 1.5 KB
/
Copy pathCal.java
File metadata and controls
49 lines (45 loc) · 1.5 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
package com.sayan;
import java.util.Scanner;
public class Cal {
public static void main(String[] args) {
Scanner in = new Scanner ( System.in );
int ans = 0;
while (true){
System.out.println ("put operator");
char op = in.next ().trim ().charAt ( 0);
if (op== '+'|| op=='-'|| op =='*'|| op == '%'|| op == '/'){
System.out.println ("1st digit");
int num1 = in.nextInt ();
System.out.println ("2nd digit");
int num2 = in.nextInt ();
if (op == '*'){
ans = num1 *num2;
}
if(op == '+'){
ans = num1 + num2;
}
if (op == '-'){
ans = num1 - num2;
}
if (op == '/'){
if (num2 !=0){
ans = num1 / num2;
}
}
if (op == '%'){
if (num2>num1 || num2 != 0){
System.out.println ("Divider never be grater or ZERO ");
ans = num1 % num2;
}
}
else if (op == 'X' || op == 'x'){
break;
}
}else {
System.out.println ("Invalid operation");
}
System.out.println ("Ans :" + ans);
}
}
}
// For handling exception , I've not use try , catch .