当前位置: 代码迷 >> 综合 >> Math的取值和基本算法
  详细解决方案

Math的取值和基本算法

热度:81   发布时间:2023-10-26 05:28:09.0

在编程中经常会用到Math的算法,所以在整理资料的时候简单的列出了一些常用的Math算法

package day_160810_common;import java.util.*;
import static java.lang.Math.PI;
import static java.lang.Math.*;public class DemoMath {public static void main(String[] args) {// abs求绝对值System.out.println(Math.abs(-1.5));// ceil,向上取值System.out.println(Math.ceil(1.2));// 2.0System.out.println(Math.ceil(-1.2));// -1.0// floor,向下取值System.out.println(Math.floor(1.2));// 1.0System.out.println(Math.floor(-1.2));// -2.0// max,min求最大最小值System.out.println(Math.max(2, 3));System.out.println(Math.min(4, 5));// pow,2的3次方System.out.println(Math.pow(2, 3));// 求整,四舍五入System.out.println(Math.round(1.2));// 1System.out.println(Math.round(1.5));// 2System.out.println(Math.PI);System.out.println(PI);// 开方System.out.println(sqrt(4));// 2}
}


  相关解决方案