Java Math tan() Function

tan Function in Java

Java Math Class

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

Here, in the page we will discuss about the tan() Function in java.

Java tan 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 tan Function of math class in Java returns the trigonometric tangent of the input angle. It is a static function so we can access it by using the Math class.

Syntax:

Math.tan(number);

Definition of Parameters:

Return Type :

Example :

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing variables in Degree
        int a = 0;
        int b = 45;
        
        // Using tan Function
        double tana = Math.tan(a);
        double tanb = Math.tan(b);
        
        // Printing Values of Variables
        System.out.println("tan Value For angle a : " + tana);
        System.out.println("tan Value For angle b : " + tanb);
    }
}
Output:

tan Value For angle a : 0.0
tan Value For angle b : 1.6197751905438615

In the above Example, We had taken two variables with two different angles stored in them. we need to store the trigonometric tangent values of the given angles in variables of double data type.

Example:

Run
import java.util.*;

public class Main{
    public static void main(String[] args){
        // Initializing variables in Degree
        int a = 0;
        int b = 60;

        // converting variables to radians
        double radiana = Math.toRadians(a);
        double radianb = Math.toRadians(b);

        // printing tan values
        System.out.println("tan value of a : " + Math.tan(radiana));
        System.out.println("tan value of b : " + Math.tan(radianb));
    }
}
Output:

tan value of a : 0.0
tan value of b : 1.7320508075688767

In the above Example, We had converted the given angle into radians because  as per the official documentation of Java, the cos() method takes the angle as radians.

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