Java.lang.Math.tan() Method

In this tutorial, we will learn how to use a tan function in Java. A tangent is nothing but, it is a line that is touching the edge of a circle at one point.

Using tan function in Java

The tan function is already available in java.lang package which is a default package in Java. It takes an argument in radian and returns a trigonometric tangent. The tangents are used to give the slopes of straight lines.

public static double tan(double angle)

where the angle is in radian

import java.util.*;
public class TanFunctionDemo {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    System.out.println("Enter incline angle in degrees");
    double degrees=sc.nextDouble();
    double radian=Math.toRadians(degrees);
    System.out.println(Math.tan(radian));
    }
}

Here we have taken input from user in degrees and using Math.toRadians function we converted it into radian and then using Math.tan function we have converted it to trigonometric tangent.

The output looks like this:

Enter incline angle in degrees
60
1.7320508075688767

Also read: Inheritance vs Delegation in Java

Leave a Reply

Your email address will not be published.