計算一個給定值的反正切
為了在 Java 中計算一個給定值的反正切,我們使用 java.lang.Math.atan() 方法。該方法接受一個雙精度值,該值需要計算其角度。返回的角度範圍位於 -pi/2 到 pi/2 之間。如果引數為 NaN,則結果為 NaN。
當引數為 0 時,輸出為一個與引數具有相同符號的 0。
宣告——java.lang.Math.atan() 方法的宣告如下:
public static double atan(double a)
其中 a 是計算其反正切的值。
我們來看一個在 Java 中計算一個給定值的反正切的程式。
示例
import java.lang.Math; public class Example { public static void main(String[] args) { // get two double numbers in degrees double x = Math.sqrt(3); double y = 1; // computing and displaying the arc tangent of these doubles System.out.println(“Arc tangent of " + x + " = " + Math.atan(x)); System.out.println("Arc tangent of " + y + " = " + Math.atan(y)); } }
輸出
Arc tangent of 1.7320508075688772 = 1.0471975511965976 Arc tangent of 1.0 = 0.7853981633974483
廣告