这个 JAVA朗,数学。罪() 返回角度在0.0和pi之间的三角正弦。如果参数为NaN或无穷大,则结果为NaN。如果参数为零,则结果为零,符号与参数相同。返回的值将介于-1和1之间。
null
语法:
public static double sin(double a) ;
参数 :要返回其正弦值的值。
返回类型: 此方法返回参数的正弦值。
实施:
这里我们将提出两个例子,其中一个简单地展示 数学罪() 方法 属于 JAVA朗包 方法和第二个是第一个例子的边情况,具体是在参数为NaN或无穷大的情况下。
例1
JAVA
// 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.499999999999999940.70710678118654750.86602540378443861.0
例2
JAVA
// Java program to demonstrate working of Math.cos() method // of java.lang package considering infinity case // Importing classes from java.lang package import java.lang.Math; public class GFG { // Main driver method 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); } } |
输出:
NaNNaNNaN
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END