Math_methods.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Write a description of class Math_methods here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class Math_methods
  8. {
  9. public static int add(int num1,int num2){
  10. return num1 + num2;
  11. }
  12. public static int minus(int num1,int num2){
  13. return num1 - num2;
  14. }
  15. public static int mult(int num1,int num2){
  16. return num1 * num2;
  17. }
  18. public static int div(int num1,int num2){
  19. return num1 / num2;
  20. }
  21. public static int mod(int num1,int num2){
  22. return num1 % num2;
  23. }
  24. public static int pow(double num1,double num2){
  25. double r = Math.pow(num1,num2);
  26. return (int)Math.round(r);
  27. }
  28. public static double sqrt(int num1){
  29. return (double) Math.sqrt(num1);
  30. }
  31. public static int min(int num1, int num2){
  32. return Math.min(num1,num2);
  33. }
  34. public static int max(int num1, int num2){
  35. return Math.max(num1,num2);
  36. }
  37. public static double exp (double num1){
  38. return Math.pow(2.718,num1);
  39. }
  40. public static double tenthpow(double num1){
  41. return Math.pow(10,num1);
  42. }
  43. public static double abs(int num1){
  44. return (double)Math.abs(num1);
  45. }
  46. public static double round(double num1){
  47. return Math.round(num1);
  48. }
  49. public static double ave(double num1,double num2){
  50. return num1 + num2 / 2;
  51. }
  52. public static long exp (int num1, int num2){
  53. int neg = -2147483647;
  54. int pos = 2147483647;
  55. long t = 0;
  56. if(num1 >= -1 || num1 <= neg){
  57. double re = Math.pow(num1,num2);
  58. return (long)re;
  59. }
  60. else if(num2 >= 1 || num2 <= pos ){
  61. double re2 = Math.pow(num2,num1);
  62. return (long)re2;
  63. }
  64. return t;
  65. }
  66. public static double sin(double num1){
  67. return (int)Math.sin(num1);
  68. }
  69. public static double cos(double num1){
  70. return (int)Math.cos(num1);
  71. }
  72. public static double tan(double num1){
  73. return (int)Math.tan(num1);
  74. }
  75. }