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.out.println("Enter incline angle in degrees");
    double degrees=sc.nextDouble();
    double radian=Math.toRadians(degrees);

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

Also read: Inheritance vs Delegation in Java

Leave a Reply

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