System.out.println(Math.abs(-3));
System.out.println(Math.sqrt(4));
//向上取整
System.out.println(Math.ceil(3.14));
System.out.println(Math.ceil(-3.14));
//向下取整
System.out.println(Math.floor(3.14));
System.out.println(Math.floor(-3.14));
//四舍五入
System.out.println(Math.round(3.1415));
System.out.println(Math.round(3.5415));
//幂操作
System.out.println(Math.pow(3, 4));
//生成[0,1)之间的随机浮点数
double a=(double)Math.random();
System.out.println(a);
//生成:0-10之间的任意整数
int b=(int)(Math.random()*10);
System.out.println(b);
//生成:20-30之间的任意整数:
int c=(int)(Math.random()*10+20);
System.out.println(c);
-------------------------------------------
输出结果:
3
2.0
4.0
-3.0
3.0
-4.0
3
4
81.0
0.26916106559991515
7
21