Groovy cos()方法

2018-12-29 16:19 更新

該方法返回指定double值的余弦值。

句法

double cos(double d)

參數

d - 此方法接受double數據類型的值。

返回值

此方法返回指定double值的余弦值。

例子

下面是一個使用這個方法的例子 -

class Example {
   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 cosine of %.1f degrees is %.4f%n", degrees, Math.cos(radians));  
   } 
}

當我們運行上面的程序,我們將得到以下結果 -

The value of pi is 3.1416 
The cosine of 45.0 degrees is 0.7071
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號