MathUtilities.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. public class MathUtilities{
  2. /**
  3. * Add two number together
  4. * @param num1 first number
  5. * @param num2 second number
  6. * @return the sum of the two numbers
  7. */
  8. public int add(int num1, int num2){
  9. int sum = num1 + num2;
  10. return sum;
  11. }
  12. /**
  13. * Add two number together
  14. * @param num1 first number
  15. * @param num2 second number
  16. * @return the sum of the two numbers
  17. */
  18. public double add(double num1, double num2){
  19. double sum = num1 + num2;
  20. return sum;
  21. }
  22. /**
  23. * Get half the value of the number
  24. * @param number the number given
  25. * @return the half of the number in double
  26. */
  27. public double half(int number) {
  28. double sum = (double) number / 2;
  29. return sum;
  30. }
  31. /**
  32. * Determine if the number is odd
  33. * @param number the number given
  34. * @return true if the number is odd, false if it is even
  35. */
  36. public boolean isOdd(int number){
  37. if(number % 2 != 0){
  38. return true;
  39. } else {
  40. return false;
  41. }
  42. }
  43. /**
  44. * Multiply the number by itself
  45. * @param number the number given
  46. * @return the result of the number multiply by itself
  47. */
  48. public int square(int number) {
  49. int result = number * number;
  50. return result;
  51. }
  52. }