Math类包含了不同分类的数学函数。
1.求平方根Math.sqrt(x)
double x = 4;
double y = Math.sqrt(x);
System.out.println(y);//输出2.0
2.求n次幂Math.pow(x,a)
double y = Math.pow(x,a); //x的a次蜜
3.Math类的常用三角形函数;
Math.sin;
Math.cos;
Math.tan;
Math.atan;
Math.atan2;
4.Math类的指数函数和他的反函数——自然对数
Math.exp;
Math.log;
5.Math类中的常量
Math.PI(π的近似值)
Math.E(e的近似值)
造型
double x = 9.997;
int y = (int) x; //y = 9;由于double类型强制转换为int,造成信息丢失,截去小数部分变为整型。
int z = Math.round(x); //z = 10