forked from SpooderManEXE/Useful-College-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.java
More file actions
60 lines (50 loc) · 2.08 KB
/
calc.java
File metadata and controls
60 lines (50 loc) · 2.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
58
59
60
import java.util.Scanner;
class calc {
int a,b;
int add()
{
return a+b;
}
int sub()
{
return a-b;
}
int mul()
{
return a*b;
}
int divide()
{ if(b!=0) return a/b; else
return -1;
}
int rem()
{ if(b!=0) return a%b;
else return -1; }
public static void main(String args[]) {
calc c=new calc();
Scanner sc = new Scanner(System.in); System.out.println("Enter two numbers: "); c.a=sc.nextInt();
c.b=sc.nextInt();
int op;
while(true)
{
System.out.print("\n1.Add\n2.Subtract\n3.Multiply\n4.Divide\n5.Remainder\n6.Change the numbers\n7.Exit\nChoose any option: ");
op=sc.nextInt();
switch(op)
{
case 1: System.out.println("A + B = "+c.add()); break;
case 2: System.out.println("A - B = "+c.sub()); break;
case 3: System.out.println("A * B = "+c.mul()); break;
case 4: if(c.divide()!=-1)
System.out.println("A / B = "+c.divide()); else
System.out.println("A / B not possible"); break;
case 5: if(c.rem()!=-1)
System.out.println("A % B = "+c.rem()); else
System.out.println("A % B not possible"); break;
case 6: System.out.println("Enter the two numbers again: "); c.a=sc.nextInt();
c.b=sc.nextInt(); break;
case 7: System.exit(0);
default: System.out.println("Enter correct option");
}
}
}
}