Java StrictMath cos()方法及实例

Java StrictMath cos()方法及实例

java.lang.StrictMath.cos() 是Java中的一个内置方法,用于返回给定角度的余弦值。当给定参数为NaN或无穷大时,该方法返回NaN。

语法

public static double cos(double num)

参数: 该方法接受一个双倍类型的参数num,指的是要返回其余弦值的弧度角。
返回值: 该方法返回参数的余弦值。
示例 :

Input: num = 62.0
Output: 0.6735071623235862

Input: num = 64.6
Output: -0.19607204956188945

下面的程序说明了java.lang.StrictMath.cos()方法:
程序1

// Java program to illustrate the
// java.lang.StrictMath.cos()
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1 = 0.0, num2= 1.0 , num3= 64.6;
     
    /* Returns trigonometric cosine of specified
    angle in radian*/
    double cosValue = StrictMath.cos(num1);
    System.out.println("The cosine of "+
                           num1+" = " + cosValue);
 
    cosValue = StrictMath.cos(num2);
    System.out.println("The cosine of "+
                           num2+" = " + cosValue);
 
    cosValue = StrictMath.cos(num3);
    System.out.println("The cosine of "+
                           num3+" = " + cosValue);}
}

输出

The cosine of 0.0 = 1.0
The cosine of 1.0 = 0.5403023058681398
The cosine of 64.6 = -0.19607204956188945

程序2

// Java program to illustrate the
// java.lang.StrictMath.cos()
import java.lang.*;
 
public class Geeks {
 
public static void main(String[] args) {
 
    double num1= -62.0, num2 = 1.0;
        double num3= (45*(Math.PI))/180;
     
    /* It returns the  cosine of specified
    angle in radian*/
    double cosValue = StrictMath.cos(num1);
    System.out.println("The cosine of "+
                           num1+" = " + cosValue);
    cosValue = StrictMath.cos(num2);
    System.out.println("The cosine of "+
                           num2+" = " + cosValue);
    cosValue = StrictMath.cos(num3);
    System.out.println("The cosine of "+
                           num3+" = " + cosValue);}
}

输出

The cosine of -62.0 = 0.6735071623235862
The cosine of 1.0 = 0.5403023058681398
The cosine of 0.7853981633974483 = 0.7071067811865476

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程