系统常用类Math

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;
		
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值