MathUtilities.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. return num1+num2;
  20. }
  21. /**
  22. * Get half the value of the number
  23. * @param number the number given
  24. * @return the half of the number in double
  25. */
  26. public double half(int number) {
  27. double val=(double)number/2;
  28. return val;
  29. }
  30. /**
  31. * Determine if the number is odd
  32. * @param number the number given
  33. * @return true if the number is odd, false if it is even
  34. */
  35. public boolean isOdd(int number){
  36. if(number%2==1)
  37. {
  38. return true;
  39. }
  40. else
  41. {
  42. return false;
  43. }
  44. }
  45. /**
  46. * Multiply the number by itself
  47. * @param number the number given
  48. * @return the result of the number multiply by itself
  49. */
  50. public int square(int number) {
  51. return number*number;
  52. }
  53. }