Math class in Java

Math class is defined inside the package java.lang .

It is used to perform mathematical operations easily and effectively. We can perform trigonometrical operations, square root, cube root, logarithmic and comparison of mathematical values very easily using the methods of this class.

Available variables or fields in Math class

public static final double E=2.718281828459045

It represents the base of natural logarithm e value. We can directly use the variable where we need to apply e value.

public static final double PI=3.141592653589793

It can be used to represent pi value and can be directly used where we need to apply pi value.

Available methods in Math class

  • static double abs(double d)
  • static float abs(float f)
  • static int abs(int i)
  • static long abs(long l)
  • static double acos(double d)
  • static double asin(double d)
  • static double atan(double d)
  • static double atan2(double y, double x)
  • static double cbrt(double d)
  • static double ceil(double d)
  • static double copySign(double magnitude, double sign)
  • static float copySign(float magnitude, float sign)
  • static double cos(double a)
  • static double cosh(double x)
  • static double exp(double a)
  • static double expm1(double x)
  • static double floor(double a)
  • static int getExponent(double d)
  • static int getExponent(float f)
  • static double hypot(double x, double y)
  • static double IEEEremainder(double f1, double f2)
  • static double log(double a)
  • static double log10(double a)
  • static double log1p(double x)
  • static double max(double a, double b)
  • static float max(float a, float b)
  • static int max(int a, int b)
  • static long max(long a, long b)
  • static double min(double a, double b)
  • static float min(float a, float b)
  • static int min(int a, int b)
  • static long min(long a, long b)
  • static double nextAfter(double start, double direction)
  • static float nextAfter(float start, double direction)
  • static double nextUp(double d)
  • static float nextUp(float f)
  • static double pow(double a, double b)
  • static double random()
  • static double rint(double a)
  • static long round(double a)
  • static int round(float a)
  • static double scalb(double d, int scaleFactor)
  • static float scalb(float f, int scaleFactor)
  • static double signum(double d)
  • static float signum(float f)
  • static double sin(double a)
  • static double sinh(double x)
  • static double sqrt(double a)
  • static double tan(double a)
  • static double tanh(double x)
  • static double toDegrees(double angrad)
  • static double toRadians(double angdeg)
  • static double ulp(double d)
  • static float ulp(float f)