Java.lang.Math.sin() 方法

描述

java.lang.Math.sin(double a) 角的三角正弦。 特别案例 −

  • 如果参数为 NaN 或无穷大,则结果为 NaN。

  • 如果参数为零,则结果为零,符号与参数相同。


声明

以下是 java.lang.Math.sin() 方法的声明。

public static double sin(double a)

参数

a − 一个角度,以弧度为单位。


返回值

此方法返回参数的正弦值。


异常

NA


示例

下面的例子展示了 lang.Math.sin() 方法的使用。

package com.tutorialspoint;

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers numbers
      double x = 45;
      double y = -180;

      // convert them to radians
      x = Math.toRadians(x);
      y = Math.toRadians(y);

      // print the trigonometric sine for these doubles
      System.out.println("Math.sin(" + x + ")=" + Math.sin(x));
      System.out.println("Math.sin(" + y + ")=" + Math.sin(y));
   }
}

让我们编译并运行上面的程序,这将产生下面的结果 −

Math.sin(0.7853981633974483)=0.7071067811865475
Math.sin(-3.141592653589793)=-1.2246467991473532E-16