下面的例子说明了如何使用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
本文通过一个示例展示了如何使用 Java 中的 Math.cos() 方法来计算角度的余弦值,并提供了完整的代码及运行结果。
1901

被折叠的 条评论
为什么被折叠?



