编程语言
首页 > 编程语言> > 115_初识Java_Math类_学习

115_初识Java_Math类_学习

作者:互联网

115_初识Java_Math类_学习

1、API的Math类解读

在这里插入图片描述
在这里插入图片描述

2、Math类常用方法练习使用

package com.llg.learnMath;

public class Learn1 {
    //程序的入口
    public static void main(String[] args) {
        //常用属性
        System.out.println("Math.PI = " + Math.PI);

        //常用方法
        System.out.println("随机数 Math.random() :\t" + Math.random());
        System.out.println("绝对值 Math.abs(-23) :\t" + Math.abs(-23));
        System.out.println("向上取值 Math.ceil(8.2) :\t" + Math.ceil(8.2));
        System.out.println("向下取值 Math.floor(8.9) :\t" + Math.floor(8.9));
        System.out.println("四舍五入 Math.round(2.4) :\t" + Math.round(2.4));
        System.out.println("四舍五入 Math.round(2.5) :\t" + Math.round(2.5));

        System.out.println("取大值 Math.max(2,3) :\t" + Math.max(2,3));
        System.out.println("取小值 Math.min(2,3) :\t" + Math.min(2,3));
    }
}

在这里插入图片描述

标签:Java,System,115,static,println,round,Math,out
来源: https://blog.csdn.net/qq_27865153/article/details/117898228