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

java之Math类

时间:2018-06-20 00:02:34      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:demo1   floor   main   max   方法   之间   数学运算   构造方法   TE   

 1 public class Demo1_Math {
 2 
 3     /*
 4      * Math类包含用于执行基本数学运算的方法,如:指数、对数、平方根等
 5      * Math中的所有方法都是静态的,构造方法是私有的
 6      * public static int abs(int a)               求一个数的绝对值
 7      * public static double ceil(double a)        向上取整,返回一个double值
 8      * public static double floor(double b)       向下取整,返回一个double值 
 9      * public static int max(int a, int b)        取两个之中的大的值    min同max类似,取最小值
10      * public static int pow(double a, double b)  对一个double值做幂运算
11      * public static double random()              取一个[0.0,1.0)之间的double的随机数
12      * public static int round(float a)           四舍五入
13      * public static double sqrt(double a)        对一个double数开平方
14      */
15     public static void main(String[] args) {
16         System.out.println(Math.abs(-10));
17         System.out.println(Math.ceil(12.7));
18         System.out.println(Math.floor(12.6));
19         System.out.println(Math.max(1, 9));
20         System.out.println(Math.pow(6.0, 2.0));
21         System.out.println(Math.random());
22         System.out.println(Math.round(3.15));
23         System.out.println(Math.sqrt(9));
24         /*
25          * 运行结果如下:
26          *  10
27             13.0
28             12.0
29             9
30             36.0
31             0.2989099810206127
32             3
33             3.0
34          */
35     }
36 }

 

java之Math类

标签:demo1   floor   main   max   方法   之间   数学运算   构造方法   TE   

原文地址:https://www.cnblogs.com/jiangjunwei/p/9201643.html

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