当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java Math.tan()用法及代码示例


java.lang.Math.tan() 用于返回角度的三角正切。

用法

public static double tan(double a)

参数

a = an angle, in radians

返回

It returns the tangent value of the argument.
  • 如果参数是正数或负数,此方法将返回切线值。
  • 如果参数是 NaN 或无穷大,则此方法将返回 NaN。
  • 如果参数为零,此方法将返回与参数相同符号的零。

例子1

public class TanExample1
{
    public static void main(String[] args) 
    {
        double a = 45;
        // converting values to radians
        double b = Math.toRadians(a);
        System.out.println(Math.tan(b));
    }
}

输出:

0.9999999999999999

例子2

public class TanExample2
{
    public static void main(String[] args) 
    {
        double a = 60;
        // converting values to radians
        double b = Math.toRadians(a);
        System.out.println(Math.tan(b));
    }
}

输出:

1.7320508075688767

例子3

public class TanExample3
{
    public static void main(String[] args) 
    {
        double a = 0.0/0;
        // converting values to radians
        double b = Math.toRadians(a);
        System.out.println(Math.tan(b));
    }
}

输出:

NaN






相关用法


注:本文由纯净天空筛选整理自 Java Math.tan() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。