Java Maths Class

    Java Maths Class

    Java supports Math class that allows you to perform various maths operation like min(), max(), avg(), algebraic, trigonometric functions and many more. If you are using int or long but the results overflow the range of value then some of the functions will return the ArithmeticException.

    Example-

    public class Simple    
    
    {    
    
        public static void main(String[] args)     
    
        {    
    
            double x = 28;    
    
            double y = 4;    
    
       double b = Math.toRadians(x);
    
         
    
            System.out.println("Maximum is: " +Math.max(x, y));   
    
             
    
            System.out.println("Square root is: " + Math.sqrt(y));   
    
    
    
            System.out.println("Power of x and y is: " + Math.pow(x, y));   
    
            System.out.println("Logarithm : " + Math.log(x));   
    
    
    
            System.out.println("log10 is: " + Math.log10(y));    
    
    
    
            System.out.println("log1p is: " +Math.log1p(x));    
    
      
    
            System.out.println("exp is: " +Math.exp(x));    
    
    
    
            System.out.println("expm1 is: " +Math.expm1(x));  
    
    
    
      System.out.println("Sine value of a is: " +Math.sin(x));    
    
    
    
            System.out.println("Cosine value is: " +Math.cos(x));  
    
    
    
            System.out.println("Tangent is: " +Math.tan(x));  
    
    
    
            System.out.println("Sine is: " +Math.asin(x));    
    
    
    
            System.out.println("Cosine is: " +Math.acos(x));  
    
    
    
            System.out.println("Tangent is: " +Math.atan(x));  
    
       
    
            System.out.println("Sine is: " +Math.sinh(x));    
    
       
    
            System.out.println("Cosine is: " +Math.cosh(x));  
    
    
    
            System.out.println("Tangent is: " +Math.tanh(x));  
    
        }    
    
    }    

    Output-

    java math output