package com.softfz.test.copy;
public class AMath {
public static void main(String[] strs) {
double num = 12.2;
System.out.println(Math.ceil(num));//13.0 向大取整(ceil 天花板)
num = 12.9;
System.out.println(Math.floor(num));//12.0 向小取整 (floor 地板)
num = 12.2;
System.out.println(Math.round(num));//输出12(round 圆, 附近 ,大概)
num = 12.5;
System.out.println(Math.round(num));//输出13
num = -12.5; //操作过程-12.5 + 0.5 -> -12.0 -> -12
System.out.println(Math.round(num)); //输出-12
num = -12.6; //-12.6 + 0.5 -> -12.1 -> -13
System.out.println(Math.round(num));//-13
num = Math.random();//0.0 ~ 1.0(不包含) 生成随机数
//0 ~ 10生成指定范围的随机数
num = Math.random() * 10;
num = Math.round(num);
//0 ~ 10.99999 生成指定范围的随机数
num = (int)(Math.random() * (10 + 1));//0 ~ 10
//3 ~ 5的范围 即是(int)(Math.random())(5-3+1)+3
//公式如下:num = (int)(Math.random() * (max - min + 1)) + min;
num = (int)(Math.random())*(5-3+1)+3;
}
}
系统常用类Math
最新推荐文章于 2021-01-09 20:03:20 发布