-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalcultor_Day4.java
More file actions
57 lines (53 loc) · 1.08 KB
/
Calcultor_Day4.java
File metadata and controls
57 lines (53 loc) · 1.08 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
package Daily_Problem;
import java.util.Scanner;
public class Calcultor_Day4 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int ans=0;
while(true)
{
System.out.print("Enter the Operator : ");
char ch=sc.next().trim().charAt(0);
if(ch=='+' || ch=='-' || ch=='*' || ch=='/' || ch=='%')
{
System.out.print("Number 1 : ");
int num1=sc.nextInt();
System.out.print("Number 2 : ");
int num2=sc.nextInt();
if(ch=='+')
{
ans=num1+num2;
}
if(ch=='-')
{
ans=num1-num2;
}
if(ch=='*')
{
ans=num1*num2;
}
if(ch=='/')
{
if(num2>0)
ans=num1/num2;
}
if(ch=='%')
{
ans=num1%num2;
}
}
else if(ch=='X' || ch=='x')
{
System.out.println("the Operation was closed");
break;
}
else
{
System.out.println("Invalid Operator !!");
break;
}
System.out.println(ans);
System.out.println("Another Operation again ");
}
}
}