-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.java
More file actions
47 lines (42 loc) · 1.05 KB
/
calc.java
File metadata and controls
47 lines (42 loc) · 1.05 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
package calc.java;
import java.util.Scanner;
public class calc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a,b,temp=0;
char op;
do
{
System.out.println("enter the operator");
op= sc.next().charAt(0);
if(op=='+'||op=='-'||op=='/'||op=='*')
{
System.out.println("enter the 2 numbers:");
a=sc.nextInt();
b=sc.nextInt();
switch(op)
{
case '+':
System.out.println("The result of 2 numbers is"+(a+b));
break;
case '-':
System.out.println("The result of 2 numbers is"+(a-b));
break;
case '/':
System.out.println("The result of 2 numbers is"+(a/b));
break;
case '*':
System.out.println("The result of 2 numbers is"+(a*b));
break;
default:
System.out.println("ente invalid operator");
break;
}
System.out.println("if you want to enter again enter 1 and if you want to exit then enter 0");
temp=sc.nextInt();
}
else
System.out.println("ente invalid operator");
}while(temp!=0);
}
}