java math.sin()_Java Math sin()用法及代码示例

java.lang.Math.sin()返回介于0.0和pi之间的角度的三角正弦。如果参数为NaN或无穷大,则结果为NaN。如果自变量为零,则结果为零,其符号与自变量相同。返回的值将在-1和1之间。

用法:

public static double sin(double a)

Parameter:

a:the value whose sine is to be returned.

返回:

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

范例1:展示java.lang.Math.sin()方法的用法。

// Java program to demonstrate working

// of java.lang.Math.sin() method

import java.lang.Math;

class Gfg {

// driver code

public static void main(String args[])

{

double a = 30;

// converting values to radians

double b = Math.toRadians(a);

System.out.println(Math.sin(b));

a = 45;

// converting values to radians

b = Math.toRadians(a);

System.out.println(Math.sin(b));

a = 60;

// converting values to radians

b = Math.toRadians(a);

System.out.println(Math.sin(b));

a = 90;

// converting values to radians

b = Math.toRadians(a);

System.out.println(Math.sin(b));

}

}

输出:

0.49999999999999994

0.7071067811865475

0.8660254037844386

1.0

范例2:当参数为NaN或无穷大时,显示java.lang.Math.sin()方法的用法。

// Java program to demonstrate working

// of java.lang.Math.cos() method infinity case

import java.lang.Math;

public class GFG {

// Driver code

public static void main(String[] args)

{

double positiveInfinity =

Double.POSITIVE_INFINITY;

double negativeInfinity =

Double.NEGATIVE_INFINITY;

double nan = Double.NaN;

double result;

// Here argument is negative infinity,

// output will be NaN

result = Math.sin(negativeInfinity);

System.out.println(result);

// Here argument is positive infinity,

// output will also be NaN

result = Math.sin(positiveInfinity);

System.out.println(result);

// Here argument is NaN, output will be NaN

result = Math.sin(nan);

System.out.println(result);

}

}

输出:

NaN

NaN

NaN

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值