Document

前言:math类中感觉最好玩的应该就是随机数

代码:

 1 package com.day13.math;
 2 
 3 import java.util.Random;
 4 
 5 /** 
 6 * 类说明 :Math
 7 * @author 作者 : chenyanlong 
 8 * @version 创建时间:2017年10月28日 
 9 */
10 public class Demo {
11 
12     public static void main(String[] args) {
13         
14         System.out.println("绝对值:"+Math.abs(-3));
15         System.out.println("向上取整:"+Math.ceil(3.13));
16         System.out.println("向下取整:"+Math.floor(-3.13));
17         System.out.println("四舍五入:"+Math.round(3.54));
18         System.out.println("随机数"+Math.random());
19         
20         //产生0-10的随机数
21         Random random=new Random();
22         int randomNum=random.nextInt(10)+1;
23         System.out.println("随机数"+randomNum);
24     }
25 }

运行效果:

原文地址:https://www.cnblogs.com/chenyanlong/p/7748533.html