Java中Math类
1.BigInteger与BigDecimal类2.Java字符集3.枚举类4.Java比较器Comparable与Comparator5.Java中System类
6.Java中Math类
7.Java内部类8.Java关键字:this、super、final9.Java代码块10.Java中继承性、多态性11.Java接口12.子类对象实例化的全过程13.static关键字14.Java中的关键字transient15.double转String结果为指数问题16.Java注解17.日期时间API18.String字符串函数19.Excepton异常类20.IO流21.Java反射机制22.JDK与JRE区别23.Java位运算24.Java方法重载25.Java属性赋值的先后顺序与对象的实例化过程Math类
java.lang.Math
提供了一系列静态方法用于执行基本数学运算的方法,如:初等指数、对数、平方根和三角函数。类似这样的工具类,其所有方法均为静态方法,并且不会创建对象。
方法名 | 说明 |
---|---|
public static int abs(int a) | 返回参数的绝对值 |
public static double ceil(double a) | 返回大于或等于参数的最小double值,等于一个整数 |
public static double floor(double a) | 返回小于或等于参数的最大double值,等于一个整数 |
public static int round(float a) | 按照四舍五入返回最接近参数int |
public static int max(int a,int b) | 返回两个int值中的较大值 |
public static int min(int a,int b) | 返回两个int值中的较小值 |
public static double pow(double a,double b) | 返回a的b次幂的值 |
public static double random() | 返回0.0到1.0的随机数,[0.0,1.0) |
acos,asin,atan,cos,sin,tan | 三角函数 |
sqrt | 平方根 |
log | 自然对数 |
exp | e为底指数 |
toDegrees(double angrad) | 弧度->角度 |
toRadians(double angdeg) | 角度->弧度 |
🌰:
@Test public void testMath() { System.out.println(Math.abs(-3.14)); // 3.14 System.out.println(Math.abs(3.14)); // 3.14 System.out.println(Math.ceil(3.14)); // 4.0 System.out.println(Math.floor(3.14)); // 3.0 System.out.println(Math.ceil(-3.14)); // -3.0 System.out.println(Math.floor(-3.14)); // -4.0 System.out.println(Math.round(3.14)); // 3 System.out.println(Math.round(3.6)); // 4 System.out.println(Math.max(100, 200)); // 200 System.out.println(Math.min(100, 200)); // 100 System.out.println(Math.pow(2, 10)); // 1024.0 // 取[0.0, 100.0) System.out.println(Math.random() * 100); // 17.36661674901805 }
本文来自博客园,作者:Lz_蚂蚱,转载请注明原文链接:https://www.cnblogs.com/leizia/p/18379477
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步