前言:math类中感觉最好玩的应该就是随机数
代码:
package com.day13.math;
import java.util.Random;
/**
* 类说明 :Math
* @author 作者 : chenyanlong
* @version 创建时间:2017年10月28日
*/
public class Demo {
public static void main(String[] args) {
System.out.println("绝对值:"+Math.abs(-3));
System.out.println("向上取整:"+Math.ceil(3.13));
System.out.println("向下取整:"+Math.floor(-3.13));
System.out.println("四舍五入:"+Math.round(3.54));
System.out.println("随机数"+Math.random());
//产生0-10的随机数
Random random=new Random();
int randomNum=random.nextInt(10)+1;
System.out.println("随机数"+randomNum);
}
}
运行效果:
