Maths Functions in Java are define within Math class. The most of math functions are static functions that’s why used always will Math class as Math.method();.

Methods of Maths Functions in Java

sqrt()

Returns square root value

Syntax

double Math.sqrt(double)
Syntax of sqrt()

Example of sqrt()

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
        //sqrt
        double x = 9.0;   
        System.out.println(Math.sqrt(x));  

    }  
}
sqrt()
Input Value

Output Value

Output Value

pow()

Returns power value of a number raised to some power

Syntax

double Math.pow(double,double);
Syntax of pow()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double x = 2;   
        double y = 16; 
        
        System.out.println(Math.pow(x, y));  



    }  
}
pow()
Input Value

Output Value

Output Value

sin()

Returns sin value

Syntax

double 
Syntax of sin()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double x = 30;    
        double y = Math.toRadians(x);  
        System.out.println(Math.sin(y));  

    }  
}
sin()
Input Value

Output Value

Output Value

exp()

Return exponent value

Syntax

double Math.exp(double)
Syntax of exp()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double x = 4;  
        System.out.println(Math.exp(x)); 

    }  
}
exp()
Input Value

Output Value

Output Value

log()

Returns log value whose base is e.

Syntax

double Math.log(double)
Syntax of log()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double x = 81.23;  
           
        System.out.println(Math.log(x));

    }  
}
log()
Input Value

Output Value

Output Value

Floor()

Return nearest down integer of the given factorial value

Syntax

Math.floor(factorial value);
Syntax of Floor()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double a = 12.2574;   
        System.out.println(Math.floor(a));  

    }  
}
Floor()
Input Value

Output Value

Output Value

Ceil()

This method returns nearest up integer value of the given fraction value

Syntax

math.ceil(function);
Syntax of Ceil()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double y = 12.369852147;  
        System.out.println(Math.ceil(y));      

    }  
}
Ceil()
Input Value

Output Value

Output Value

round()

This function rounds off the decimal post digits of the given fractional number. It will work as suppose there is one digit after decimal in fractional number and if it is 5 or greater than 5 then it will be treat as 10 otherwise 0, and so on for two ,three…. digits after decimal position.

Syntax

Math.round (fractional number);
Syntax of round()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        double y = 12.36;    
        System.out.println(Math.round(y));      

    }  
}
round()
Input Value

Output Value

Output Value

abs()

this function returns the positive value of the given negative value but vice-versa not true.

Syntax

public static int abs(int i)  
public static double abs(double d)  
public static float abs(float f)  
public static long abs(long lng)  
Syntax of abs()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        float x = -23.5f;       
        long y = 255525; 
        double z = 258.3674;  
        int r = 12;
      
        System.out.println(Math.abs(x));  
        System.out.println(Math.abs(y));  
        System.out.println(Math.abs(z));  
        System.out.println(Math.abs(r));


    }  
}
abs()
Input Value

Output Value

Output Value

max()

This function returns the maximum number of the given two numbers. Numbers array of any numeric type.

Syntax

Math.max(value1,value2);
Syntax of max()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        int x = 25;  
        int y = 58;
          
        System.out.println(Math.max(x, y)); 


    }  
}
max()
Input Value

Output Value

Output Value

min()

This function returns the minimum number of the given two numbers. Numbers array of any numeric type.

Syntax

Math.min(value1,value2);
Syntax of min()

Example

Input Value

public class mathsm {
    public static void main(String[] args)   
    {  
    
        int x = 25;  
        int y = 58;
          
        System.out.println(Math.min(x, y)); 


    }  
}
min()
Input Value

Output Value

Output Value

If you have any queries regarding this article or if I have missed something on this topic, please feel free to add in the comment down below for the audience. See you guys in another article.

To know more about JAVA Wikipedia please click here .

Stay Connected Stay Safe, Thank you


Basic Engineer

Hey Readers! We have more than fifteen years of experience in Software Development, IoT, Telecom, Banking, Finance and Embedded domain. Currently we are actively working on Data Science, ML and AI with multiple market leaders worldwide. Happy Reading. Cheers!

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *