集册 Java实例教程 使用Math类中的三角函数

使用Math类中的三角函数

欢马劈雪     最近更新时间:2020-01-02 10:19:05

895
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Math类中的三角函数
/* 
*来 自
 N o w  J a v a  . c o m
*/

public class TrigonometricDemo {

    public static void main(String[] args) {

        double degrees = 45.0;

        double radians = Math.toRadians(degrees);


        System.out.format("The value of pi " + "is %.4f%n", Math.PI);


        System.out.format("The sine of %.1f " + "degrees is %.4f%n",

                degrees, Math.sin(radians));


        System.out.format("The cosine of %.1f " + "degrees is %.4f%n",

                degrees, Math.cos(radians));


        System.out.format("The tangent of %.1f " + "degrees is %.4f%n",

                degrees, Math.tan(radians));


        System.out.format("The arcsine of %.4f " + "is %.4f degrees %n",

                Math.sin(radians),

                Math.toDegrees(Math.asin(Math.sin(radians))));//时代Java - nowjava.com


        System.out.format("The arccosine of %.4f " + "is %.4f degrees %n",

                Math.cos(radians),

                Math.toDegrees(Math.acos(Math.cos(radians))));


        System.out.format("The arctangent of %.4f " + "is %.4f degrees %n",

                Math.tan(radians),

                Math.toDegrees(Math.atan(Math.tan(radians))));

    }

}


展开阅读全文