|
123456789101112131415161718192021222324252627282930313233343536 |
- package com.educoder.bridge.service;
-
- /**
- * @Author: youys
- * @Date: 2023/2/27
- * @Description:
- */
- public class CalculatorService {
-
- public int add(int a, int b) {
- return a + b;
- }
-
- public int subtract(int a, int b) {
- return a - b;
- }
-
- public int multiply(int a, int b) {
- return a * b;
- }
-
- public double divide(double a, double b) {
- if (b == 0) {
- throw new IllegalArgumentException("Cannot divide by zero!");
- }
- return a / b;
- }
-
- public double sqrt(double a) {
- if (a < 0) {
- throw new IllegalArgumentException("Cannot calculate square root of negative number!");
- }
- return Math.sqrt(a);
- }
-
- }
|