Math.cos()的使用说明

下面的例子说明了如何使用lang.Math.cos()方法:

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 45.0;
      double y = 180.0;

      // convert them to radians
      x = Math.toRadians(x);
      y = Math.toRadians(y);

      // print their cosine
      System.out.println("Math.cos(" + x + ")=" + Math.cos(x));
      System.out.println("Math.cos(" + y + ")=" + Math.cos(y));


   }
}
让我们来编译和运行上面的程序,这将产生以下结果:

Math.cos(0.7853981633974483)=0.7071067811865476
Math.cos(3.141592653589793)=-1.0

你可能感兴趣的:(javase)