码迷,mamicode.com
首页 > 编程语言 > 详细

java Math类方法使用

时间:2020-06-09 16:57:11      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:code   eth   结果   print   out   round   stat   sqrt   java   

 1 package math;
 2 
 3 public class MathMethod {
 4     public static void main(String[] args) { System.out.println(Math.abs(10));//10
 5     System.out.println( Math.abs(-10));//10
 6     //pow
 7     System.out.println((int) Math.pow(2,4));//16
 8     System.out.println(Math.pow(2,-4));
 9 
10     System.out.println(Math.ceil(1.001));
11     System.out.println(Math.floor(-1.001));
12 
13     System.out.println(Math.round(1.54));
14 
15     System.out.println(Math.sqrt(9.0));
16 
17     System.out.println(Math.random());
18     int a=2;
19     int b=7;
20     int num=a+(int)(Math.random()*(b-a+1));
21     System.out.println("num="+ num);
22 
23     System.out.println(Math.max(1.0,7.8));
24     System.out.println(Math.min(12l,78l));
25 
26     }
27 }

结果:

10
10
16
0.0625
2.0
-2.0
2
3.0
0.2695117759347122
num=7
7.8
12

 

java Math类方法使用

标签:code   eth   结果   print   out   round   stat   sqrt   java   

原文地址:https://www.cnblogs.com/-xuewuzhijing-/p/13073234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!