Java Math acos() Function

acos Function

Java Math Class

Java Math class provides several basic and advance methods to perform different operations on math calculations like max(), min(), sin(), round(), ceil(), floor(), acos() etc.
The java.lang.Math class contains various methods for performing basic numeric operations

Here, in the page we will discuss about the acos() Method in java.

Java acos() Function :

Java Collection contains Math class and The class Math contains methods for performing basic and advance numeric operations such as the exponential, logarithm, square root, and trigonometric functions.
The Java acos() Function returns the arc cosine of a given input. arc cosine is also known as inverse of cosine.
The given output should be in the range of 0 to 1. if the given input is NaN or greater than 1 then the output will be NaN.

Syntax:

Math.acos(number);

Definition of Parameters:

Return Type :

clear() Function in ArrayList

clone() Function in ArrayList

add() Function in ArrayList

addall() Function in ArrayList

Example For Numbers in Valid Range:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        double a = 0;
        double b = 0.1;
        double c = 1;
        
        // Printing acos value for 0
        System.out.println("acos value of 0 is : " + Math.acos(a));
        
        // Printing acos value for range between 0 and 1
        System.out.println("acos value for number in range is : " + Math.acos(b));
        
        // Printing acos value for 1
        System.out.println("acos value for 1 is : " + Math.acos(c));
    }
}
Output:

acos value of 0 is : 1.5707963267948966
acos value for number in range is : 1.4706289056333368
acos value for 1 is : 0.0

In the above Example, We had taken examples for double values with range includes 0 to 1

Example for Negative Out of Range Numbers:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        double a = 10;
        double b = 2.5;
        double c = 1.1;
        
        // Printing acos values for out of range values
        System.out.println(Math.acos(a));
        System.out.println(Math.acos(b));
        System.out.println(Math.acos(c));
    }
}
Output:

NaN
NaN
NaN

In the above Example, We had taken out of range numbers for which we will be getting NaN output.

Example for Negative and NaN Value Number :

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        double a = -10;
        double b = -2;
        
        // Printing acos values for Negative Numbers
        System.out.println(Math.acos(a));
        System.out.println(Math.acos(b));
    }
}
Output:

NaN
NaN

In the above Example, We had taken negative value and the NaN value which gives NaN output.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription