Java中的三角函数及其示例

Math类包含执行基本数值运算的方法,如初等指数、对数、平方根和三角函数。

null
  1. JAVA朗,数学。sin()方法: 是一个内置的方法,返回 正弦 作为参数传递的值的。此函数中传递的值应为 弧度 .如果参数为NaN或无穷大,则结果为NaN。如果参数为零,则结果为零,符号与参数相同。

    语法:

    Math.sin(double radians)

    参数: 该方法以弧度为单位接受一个强制参数。

    返回: 它返回一个双精度值。返回值是传递的指定双精度值的正弦值。

    例1: 演示sin()用法的程序

    // Java program for sin() method
    import java.util.*;
    class GFG {
    // Driver Code
    public static void main(String args[])
    {
    double degrees = 45.0 ;
    // convert degrees to radians
    double radians = Math.toRadians(degrees);
    // sin() method to get the sine value
    double sinValue = Math.sin(radians);
    // prints the sine value
    System.out.println( "sin(" + degrees + ") = " + sinValue);
    }
    }

    
    

    输出:

    sin(45.0) = 0.7071067811865475
    
  2. JAVA朗,数学。cos(): 是一个内置的方法,返回 余弦 作为参数传递的值的。此函数中传递的值应为 弧度 .如果参数为NaN或无穷大,则结果为NaN。

    语法:

    Math.cos(double radians)

    参数: 该方法以弧度为单位接受一个强制参数。

    返回: 它返回一个双精度值。返回值是传递的指定双精度值的余弦。

    例2: 演示cos()用法的程序

    // Java program for cos() method
    import java.util.*;
    class GFG {
    // Driver Code
    public static void main(String args[])
    {
    double degrees = 45.0 ;
    // convert degrees to radians
    double radians = Math.toRadians(degrees);
    // cos() method to get the cosine value
    double cosValue = Math.cos(radians);
    // prints the cosine value
    System.out.println( "cos(" + degrees + ") = " + cosValue);
    }
    }

    
    

    输出:

    cos(45.0) = 0.7071067811865476
    
  3. JAVA朗,数学。谭(): 是一个内置的方法,返回 切线 作为参数传递的值的。此函数中传递的值应为 弧度 .如果参数为NaN或无穷大,则结果为NaN。如果参数为零,则结果为零,符号与参数相同。 语法:
    Math.tan(double radians)

    参数: 该方法以弧度为单位接受一个强制参数。

    返回: 它返回一个双精度值。返回的值是传递的指定双精度值的切线。

    例3: 演示tan用法的程序()

    // Java program for tan() method
    import java.util.*;
    class GFG {
    // Driver Code
    public static void main(String args[])
    {
    double degrees = 45.0 ;
    // convert degrees to radians
    double radians = Math.toRadians(degrees);
    // cos() method to get the tangent value
    double tanValue = Math.tan(radians);
    // prints the tangent value
    System.out.println( "tan(" + degrees + ") = " + tanValue);
    }
    }

    
    

    输出:

    tan(45.0) = 0.9999999999999999
    
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享