|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   yanqi_vip  阅读(12)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示