Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Java

เมธอด toDegrees() ใน Java - แปลง Radian เป็น Degree

java.lang.Math.toDegrees(double angrad) แปลงมุมจาก Radian เป็น Degree ประมาณการ การแปลงโดยทั่วไปไม่ Exacting ควรไม่คาดหวังว่า cos(toRadians(90.0)) จะเท่ากับ 0.0 พอดี

Argument angrad อยู่ใน Radian

ตัวอย่างที่ 1: toDegrees() กับค่าต่างๆ

import java.lang.*;

public class Demo {
    public static void main(String[] args) {
        double x = 45;
        double y = -180;
        x = Math.toDegrees(x);
        y = Math.toDegrees(y);
        System.out.println("Math.tanh(" + x + ")=" + Math.tanh(x));
        System.out.println("Math.tanh(" + y + ")=" + Math.tanh(y));
    }
}

ผลลัพธ์

Math.tanh(2578.3100780887044)=1.0
Math.tanh(-10313.240312354817)=-1.0

ตัวอย่างที่ 2: toDegrees() กับ Math.PI

import java.lang.*;

public class Demo {
    public static void main(String[] args) {
        double x = Math.PI;
        System.out.println(Math.toDegrees(x));  // 180.0
    }
}

ผลลัพธ์

180.0

สูตร: Degrees = Radians × (180/π) เมธอดคู่คือ Math.toRadians(double angdeg) แปลง Degree เป็น Radian