Math_methods.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. //Console.Math_basic = new Console();
  10. //Integer i = Console.getIntegerInput("Enter an integer");
  11. //Double d = Console.getDoubleInput("Enter a double.");
  12. public static int add(int num1,int num2){
  13. return num1 + num2;
  14. }
  15. public static int minus(int num1,int num2){
  16. return num1 - num2;
  17. }
  18. public static int mult(int num1,int num2){
  19. return num1 * num2;
  20. }
  21. public static int div(int num1,int num2){
  22. return num1 / num2;
  23. }
  24. public static int mod(int num1,int num2){
  25. return num1 % num2;
  26. }
  27. public static int pow(double num1,double num2){
  28. double r = Math.pow(num1,num2);
  29. return (int)Math.round(r);
  30. }
  31. public static double sqrt(int num1){
  32. return (double) Math.sqrt(num1);
  33. }
  34. public static int min(int num1, int num2){
  35. return Math.min(num1,num2);
  36. }
  37. public static int max(int num1, int num2){
  38. return Math.max(num1,num2);
  39. }
  40. public static double exp (double num1){
  41. return Math.pow(2.718,num1);
  42. }
  43. public static double tenthpow(double num1){
  44. return Math.pow(10,num1);
  45. }
  46. public static double abs(int num1){
  47. return (double)Math.abs(num1);
  48. }
  49. public static double round(double num1){
  50. return Math.round(num1);
  51. }
  52. public static double ave(double num1,double num2){
  53. return num1 + num2 / 2;
  54. }
  55. public static long exp (int num1, int num2){
  56. int neg = -2147483647;
  57. int pos = 2147483647;
  58. long t = 0;
  59. if(num1 >= -1 || num1 <= neg){
  60. double re = Math.pow(num1,num2);
  61. return (long)re;
  62. }
  63. else if(num2 >= 1 || num2 <= pos ){
  64. double re2 = Math.pow(num2,num1);
  65. return (long)re2;
  66. }
  67. return t;
  68. }
  69. public static double sin(double num1){
  70. return (int)Math.sin(num1);
  71. }
  72. public static double cos(double num1){
  73. return (int)Math.cos(num1);
  74. }
  75. public static double tan(double num1){
  76. return (int)Math.tan(num1);
  77. }
  78. }