|NO.Z.00011|——————————|BigDataEnd|——|Java&核心类库.V11|——|Java.v11|Math类|概念使用|

一、数学处理类
### --- Math类的基本概念

~~~     ——>        java.lang.Math类主要用于提供执行数学运算的方法,如:对数,平方根。
二、常用的方法
方法声明 功能介绍
static int max(int a, int b) 返回两个参数中的最大值
static int min(int a, int b) 返回两个参数中的最小值
static double pow(double a, double b) 返回第一个参数的幂
static int abs(int a) 返回参数指定数值的绝对值
static long round(double a) 返回参数四舍五入的结果
static double sqrt(double a) 返回0.0到1.0的随机数
static double random()  
三、编程代码
package com.yanqi.task11;

/**
 * 编程实现对Math类中常用方法的测试
 */
public class MathTest {

    public static void main(String[] args) {

        System.out.println("获取两个整数中最大值的结果是:" + Math.max(10, 20)); // 20
        System.out.println("获取两个整数中最小值的结果是:" + Math.min(10, 20)); // 10
        System.out.println("获取次方的结果是:" + Math.pow(2, 3)); // 8.0  体现double类型
        System.out.println("获取绝对值的结果是:" + Math.abs(-5)); // 5
        System.out.println("进行四舍五入的结果是:" + Math.round(3.14)); // 3
        System.out.println("该整数的平方根是:" + Math.sqrt(16)); // 4.0
        System.out.println("生成的随机数是:" + Math.random()); // 随机数
    }
}
四、编译打印
D:\JAVA\jdk-11.0.2\bin\java.exe "-javaagent:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=50491:D:\IntelliJIDEA\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath E:\NO.Z.10000——javaproject\NO.H.00001.javase\javase\out\production\javase com.yanqi.task11.MathTest
获取两个整数中最大值的结果是:20
获取两个整数中最小值的结果是:10
获取次方的结果是:8.0
获取绝对值的结果是:5
进行四舍五入的结果是:3
该整数的平方根是:4.0
生成的随机数是:0.26255202285928325

Process finished with exit code 0

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on 2022-04-04 14:41  yanqi_vip  阅读(19)  评论(0)    收藏  举报

导航