Skip to content

Commit 14acf1d

Browse files
Added Calculator Feature
1 parent 438b0d4 commit 14acf1d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/main/Calculator.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class Calculator {
2+
3+
// Method to add two numbers
4+
public int add(int a, int b) {
5+
return a + b;
6+
}
7+
8+
// Method to subtract two numbers
9+
public int subtract(int a, int b) {
10+
return a - b;
11+
}
12+
13+
// Method to multiply two numbers
14+
public int multiply(int a, int b) {
15+
return a * b;
16+
}
17+
18+
// Method to divide two numbers
19+
public double divide(int a, int b) {
20+
if (b != 0) {
21+
return (double) a / b;
22+
} else {
23+
throw new ArithmeticException("Division by zero is not allowed.");
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)