You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CalculatorService.java 723 B

3 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536
  1. package com.educoder.bridge.service;
  2. /**
  3. * @Author: youys
  4. * @Date: 2023/2/27
  5. * @Description:
  6. */
  7. public class CalculatorService {
  8. public int add(int a, int b) {
  9. return a + b;
  10. }
  11. public int subtract(int a, int b) {
  12. return a - b;
  13. }
  14. public int multiply(int a, int b) {
  15. return a * b;
  16. }
  17. public double divide(double a, double b) {
  18. if (b == 0) {
  19. throw new IllegalArgumentException("Cannot divide by zero!");
  20. }
  21. return a / b;
  22. }
  23. public double sqrt(double a) {
  24. if (a < 0) {
  25. throw new IllegalArgumentException("Cannot calculate square root of negative number!");
  26. }
  27. return Math.sqrt(a);
  28. }
  29. }