package com.java9.stu;
public class MathTest {
public static void main(String[] args) {
//将弧度转换成角度
System.out.println("Math.toDegrees(1.57):"+Math.toDegrees(1.57)+"°");
//将角度转换成弧度
System.out.println("Math.toRadians(90):"+Math.toRadians(90)+"弧度");
//计算反余弦,返回角度范围在0.0~pi之间
System.out.println("Math.acos(2.2):"+Math.acos(2.2));
//计算反正弦,返回角度范围在-pi/2到pi/2 之间
System.out.println("Math.asin(0.8):"+Math.asin(0.8));
//计算反正切返回角度范围在-pi/2到pi/2之间
System.out.println("Math.atan(2.3):"+Math.atan(2.3));
//计算三角余弦
System.out.println("Math.cos(1.57):"+Math.cos(1.57));
//计算双曲余弦
System.out.println("Math.cosh(1.2):"+Math.cosh(1.2));
//计算正弦
System.out.println("Math.sin(1.57):"+Math.sin(1.57));
//计算双曲正弦
System.out.println("Math.sinh(1.2):"+Math.sinh(1.2));
//计算三角正切
System.out.println("Math.tan(0.8):"+Math.tan(0.8));
//计算双曲正切
System.out.println("Math.tanh(2.1):"+Math.tanh(2.1));
//将矩形坐标(x,y)转换成(y,z)
System.out.println("Math.atan2(0.1, 0.2):"+Math.atan2(0.1, 0.2));
/************取整运算****************/
//取整,返回小于目标数的最大整数
System.out.println("Math.floor(-1.2):"+Math.floor(-1.2));
//取整,返回小于目标数的最小整数
System.out.println("Math.ceil(-1.2):"+Math.ceil(-1.2));
//四舍五入
System.out.println("Math.round(2.5):"+Math.round(2.5));
/************乘方,开方,指数运算*****************/
//计算平方根
System.out.println("Math.sqrt(2.3):"+Math.sqrt(2.3));
//计算立方根
System.out.println("Math.cbrt(9):"+Math.cbrt(9));
//返回e的N次幂
System.out.println("Math.exp(2):"+Math.exp(2));
}
}
运行后输出
Math.toDegrees(1.57):89.95437383553926°
Math.toRadians(90):1.5707963267948966弧度
Math.acos(2.2):NaN
Math.asin(0.8):0.9272952180016123
Math.atan(2.3):1.1606689862534056
Math.cos(1.57):7.963267107332633E-4
Math.cosh(1.2):1.8106555673243747
Math.sin(1.57):0.9999996829318346
Math.sinh(1.2):1.5094613554121725
Math.tan(0.8):1.0296385570503641
Math.tanh(2.1):0.9704519366134539
Math.atan2(0.1, 0.2):0.4636476090008061
Math.floor(-1.2):-2.0
Math.ceil(-1.2):-1.0
Math.round(2.5):3
Math.sqrt(2.3):1.51657508881031
Math.cbrt(9):2.080083823051904
Math.exp(2):7.38905609893065