1. Math类概述和方法使用

  • Math类概述

    • Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。

  • 成员方法

    • public static int abs(int a)

    • public static double ceil(double a)

    • public static double floor(double a)

    • public static int max(int a,int b) 

    • public static double pow(double a,double b)

    • public static double random()

    • public static int round(float a) 

    • public static double sqrt(double a)

package com.heima.otherclass;

public class Demo1_Math {

    /**
    Math 类包含用于执行基本数学运算的方法,如初等指数、对数、平方根和三角函数。 

    与 StrictMath 类的某些数学方法不同,并非 Math 类所有等价函数的实现都定义为返回逐位相同的结果。此类在不需要严格重复的地方可以得到更好的执行。

     */
    public static void main(String[] args) {
        // 常量π和指数e
        System.out.println(Math.PI);
        System.out.println(Math.E);
        
        // 常见方法
        System.out.println(Math.abs(-10));
        System.out.println(Math.ceil(12.3));
        System.out.println(Math.floor(12.3));
        System.out.println(Math.max(2,3));
        System.out.println(Math.min(1,-1));
        System.out.println(Math.pow(2,3));
        System.out.println(Math.random());
        System.out.println(Math.round(4.49f));
        System.out.println(Math.round(780999.99144));
        System.out.println(Math.sqrt(2));
        
    }

}
View Code

相关文章:

  • 2021-11-05
  • 2021-10-15
  • 2021-12-22
  • 2021-11-25
  • 2021-11-30
  • 2021-06-06
  • 2021-10-30
  • 2021-07-17
猜你喜欢
  • 2021-04-05
  • 2021-09-19
  • 2021-04-16
  • 2021-06-09
  • 2021-04-16
  • 2021-09-23
  • 2021-10-15
相关资源
相似解决方案