Java 中的数学类与条件语句使用指南
1. Math 类概述
在 Java 编程里,Math 类提供了众多用于执行基本数学运算的方法,像计算绝对值、指数、对数、平方根以及三角函数等。以下是 Math 类中部分常用方法的介绍:
| Math 方法 | 描述 |
| — | — |
| Math.abs(int n) | 绝对值(n 或 0 - n,取较大值) |
| Math.acos(double d) | d 的反余弦值 |
| Math.asin(double d) | d 的反正弦值 |
| Math.atan(double d) | d 的反正切值 |
| Math.ceil(double d) | 向上取整(不小于 d 的最小整数) |
| Math.cos(double d) | d 的余弦值 |
| Math.exp(double d) | e 的 d 次幂(e = 2.718…) |
| Math.floor(double d) | 向下取整(不大于 d 的最大整数) |
| Math.log(double d) | d 的自然对数 |
| Math.pow(double a, double b) | a 的 b 次幂 |
| Math.random() | 生成一个 0.0(包含)到 1.0(不包含)之间的随机数 |
| Math.round(float f) | 将 f 四舍五入为最接近的 int 值 |
| Math.round(double d) | 将 d 四舍五入为最接近的 long 值 |
| Math.sin(double d)
超级会员免费看
订阅专栏 解锁全文
936

被折叠的 条评论
为什么被折叠?



