2020-12-07

30 常用工具类(二)

Math 数学工具类(方法为静态方法)

1 向上取整(找最近比它大的数):ceil(天花板)

 System.out.println(Math.ceil(7.1)); //返回值是double类型

2 向下取整(找最近比它小的数):floor(地板)

 System.out.println(Math.floor(5.1)); //返回值是double类型

3 四舍五入:round

 System.out.print(Math.round(5.1)); System.out.print(Math.round(6.6)); //返回值是double类型`

4 0-1之间的随机数(小数):random

 System.out.print(Math.random()); //返回值是double类型

5 最大值:max

 System.out.print(Math.max(5,1)); //返回值是输入的实参中范围最大的类型

6 最小值min

System.out.print(Math.min(5,33.4));//返回值是输入的实参中范围最大的类型(如int,double返回的是double)

7 n的m次方

System.out.print(Math.pow(5,2));//形参为double类型,可以实参不是double类型,因为自动类型转换//返回值是double类型//返回第一个参数的第二个参数次幂的值








原文转载:http://www.shaoqun.com/a/495076.html

landing:https://www.ikjzd.com/w/2368

costco:https://www.ikjzd.com/w/1680

tenso:https://www.ikjzd.com/w/1552.html


Math数学工具类(方法为静态方法)1向上取整(找最近比它大的数):ceil(天花板)System.out.println(Math.ceil(7.1));//返回值是double类型2向下取整(找最近比它小的数):floor(地板)System.out.println(Math.floor(5.1));//返回值是double类型3四舍五入:roundSystem.out.print(Math.
笨鸟海淘:笨鸟海淘
跨境通电子商务:跨境通电子商务
东莞观音山端午节有表演吗?2020端午节观音山有什么活动?:东莞观音山端午节有表演吗?2020端午节观音山有什么活动?
急需,厦门三天两夜旅游攻略?:急需,厦门三天两夜旅游攻略?
深圳西冲三门岛环境怎么样?:深圳西冲三门岛环境怎么样?

No comments:

Post a Comment