//Math
Math.abs(123); //取绝对值
Math.cbrt(8); //开立方根
Math.sqrt(9); //开平方根 正的
Math.ceil(4.6); //向上取整
Math.floor(4.6); //向下取整
Math.log10(100); //求以10为底的对数
Math.max(3, 5); //求最大值
Math.min(2, 78); //最小值
Math.pow(2, 7); //2的7次方
Math.random(); //随机一个数 0-1之间 要改变界线直接乘最大值
Math.round(5.5); //四舍五入
Math.round(5.4);
//更多查看API文档或自动提示
//随机函数类
Random random = new Random();
int i = random.nextInt(2)+1; //界限 不加1为0-1 加了1为1-2
//若要20-40则界限选20,再加20
System.out.println(i);
格外补充案例
System.out.println(Math.E); //Math
System.out.println(Math.PI);
System.out.println(Math.abs(-3.2));
System.out.println(Math.cbrt(8)); //开立方
System.out.println(Math.sqrt(9)); //开正平方
System.out.println(Math.ceil(3.3)); //向上取证整
System.out.println(Math.floor(3.3)); //向下取整
System.out.println(Math.log10(100)); //10为底求100的对数
System.out.println(Math.max(23, 2.44));
System.out.println(Math.pow(2, 3)); //求幂
System.out.println(Math.round(3.6)); //四舍五入
System.out.println(Math.round(3.3));
System.out.println(Math.random());
System.out.println(Math.tan());
三角函数,一般数学计算均可在Math中提示出现,但需要对数值结果做处理。
有待更新