复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45/** * Main : * * @author:chenbenlong * @Time:2022/9/2 * @Version:1.0 **/ public class Main { public static void main(String[] args) { //Math获取绝对值 System.out.println("11绝对值:"+Math.abs(11)); //负数的绝对值就是它的正数 System.out.println("-11绝对值:"+Math.abs(-11)); //进一法 System.out.println("9.1进一法:"+Math.ceil(9.1)); //退一法 System.out.println("9.1退一法:"+Math.floor(9.1)); //四舍五入法 System.out.println("9.49四舍五入:"+Math.round(9.49)); System.out.println("9.50四舍五入:"+Math.round(9.50)); //取一个大于等于0.01,小于1.0的随机数。返回类型是double System.out.println("取一个大于等于0.01,小于1.0的随机数。返回类型是double"+Math.random()); //取100以内的随机数 System.out.println("100以内的随机数:"+(int)Math.floor(Math.random()*100)); //获取两个数中的最大值 System.out.println("获取1和2之间的最大值:"+Math.max(1,2)); //获取两个数中的最小值 System.out.println("获取1和2之间的最小值:"+Math.min(1,2)); //计算平方根 System.out.println("获取16的平方根:"+Math.sqrt(16)); //计算x的y次方 System.out.println("计算2的4次方:"+Math.pow(2,4)); //计算立方根 System.out.println("获取27的立方根"+Math.cbrt(27)); } }
最后
以上就是难过短靴最近收集整理的关于Math类的常用方法,进一法,退一法,四舍五入法,绝对值,随机数 ,平方根 xy的次方的全部内容,更多相关Math类的常用方法,进一法,退一法,四舍五入法,绝对值,随机数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复