数学类

概述:提供科学计算的一些方法。

示例:

package com.itcode.demo4;  


import java.text.DateFormat;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
import java.util.Random;  

/** 
 * @Auther: 成都码到功成学员 
 * @Description: 
 * Math类 
 */  
public class TestMath {  
    public static void main(String[] args) throws ParseException {  
        //向上取整  
        System.out.println(Math.ceil(5.3));  
        //向下取整  
        System.out.println(Math.floor(5.3));  
        // 四舍五入  
        System.out.println(Math.round(5.3));  
        System.out.println(Math.round(5.6));  
        //绝对值  
        System.out.println(Math.abs(-54));  
        //平方根、a的b次幂等操作  
        System.out.println(Math.sqrt(64));  
        //i的j次方  
        System.out.println(Math.pow(3, 4));  
        //关于3.14  
        System.out.println(Math.PI);  
        // 随机数[0,1)  
        System.out.println(Math.random());  
        // 随机生成10-25的随机数  
        System.out.println(10+new Random().nextInt(15));  
    }  
}

效果:

Last updated

Was this helpful?