Skip to content

Commit a62efd8

Browse files
committed
Basic Calculator
1 parent c768485 commit a62efd8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

Calculator.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
public class Calculator
2+
{
3+
public void Calculator()
4+
{
5+
6+
}
7+
public int add(int a, int b)
8+
{
9+
return (a+b);
10+
}
11+
12+
public int subtract(int a, int b)
13+
{
14+
return (a - b);
15+
}
16+
17+
public int multiply(int a, int b)
18+
{
19+
return (a * b);
20+
}
21+
22+
public int divide(int a, int b)
23+
{
24+
if (b == 0)
25+
{
26+
System.out.println("Error! Dividing by zero is not allowed");
27+
return 0;
28+
}
29+
else
30+
{
31+
return (a / b);
32+
}
33+
}
34+
35+
public int modulo(int a, int b)
36+
{
37+
if (b == 0)
38+
{
39+
System.out.println("Error! Diving by zero is not allowed");
40+
return 0;
41+
}
42+
else
43+
{
44+
return (a % b);
45+
}
46+
}
47+
48+
public static void main(String[] args)
49+
{
50+
Calculator myCalculator = new Calculator();
51+
System.out.println(myCalculator.add(5, 7));
52+
System.out.println(myCalculator.subtract(45, 11));
53+
54+
}
55+
}

0 commit comments

Comments
 (0)