Java-NumberMath类
Java-NumberMath类
public class NumberAndMath {
//(Integer、Long、Byte、Double、Float、Short)都是抽象类 Number 的子类
// Math 包含了用于执行基本数学运算的属性和方法,如初等指数、对数、平方根和三角函数
private static void test(double num) {
System.out.println("Math.floor(" + num + ")=" + Math.floor(num));
System.out.println("Math.round(" + num + ")=" + Math.round(num));
System.out.println("Math.ceil(" + num + ")=" + Math.ceil(num));
}
public static void main(String[] args) {
System.out.println("90度的正弦值" + Math.sin(Math.PI / 2));
System.out.println("0度的余弦值" + Math.cos(0));
System.out.println("60度的正切值" + Math.tan(Math.PI / 3));
System.out.println("1的反正切值" + Math.atan(1));
System.out.println("PI /2的角度值" + Math.toDegrees(Math.PI / 2));
double[] nums = {1.4, 1.5, 1.6, -1.4, -1.5, -1.6};
for (double num : nums) {
test(num);
}
/*
序号 方法与描述
1 xxxValue()
将 Number 对象转换为xxx数据类型的值并返回。
2 compareTo()
将number对象与参数比较。
3 equals()
判断number对象是否与参数相等。
4 valueOf()
返回一个 Number 对象指定的内置数据类型
5 toString()
以字符串形式返回值。
6 parseInt()
将字符串解析为int类型。
7 abs()
返回参数的绝对值。
8 ceil()
返回大于等于( >= )给定参数的的最小整数,类型为双精度浮点型。
9 floor()
返回小于等于(<=)给定参数的最大整数 。
10 rint()
返回与参数最接近的整数。返回类型为double。
11 round()
它表示四舍五入,算法为 Math.floor(x+0.5),即将原来的数字加上 0.5 后再向下取整,所以,Math.round(11.5) 的结果为12,Math.round(-11.5) 的结果为-11。
12 min()
返回两个参数中的最小值。
13 max()
返回两个参数中的最大值。
14 exp()
返回自然数底数e的参数次方。
15 log()
返回参数的自然数底数的对数值。
16 pow()
返回第一个参数的第二个参数次方。
17 sqrt()
求参数的算术平方根。
18 sin()
求指定double类型参数的正弦值。
19 cos()
求指定double类型参数的余弦值。
20 tan()
求指定double类型参数的正切值。
21 asin()
求指定double类型参数的反正弦值。
22 acos()
求指定double类型参数的反余弦值。
23 atan()
求指定double类型参数的反正切值。
24 atan2()
将笛卡尔坐标转换为极坐标,并返回极坐标的角度值。
25 toDegrees()
将参数转化为角度。
26 toRadians()
将角度转换为弧度。
27 random()
返回一个随机数。
*/
}
}
本文来自博客园,作者:OCEANEYES.GZY,转载请注明原文链接:https://www.cnblogs.com/oceaneyes-gzy/p/12317379.html
关于作者
👋 读书城南,🤔 在未来面前,我们都是孩子~
- 📙 一个热衷于探索学习新方向、新事物的智能产品经理,闲暇时间喜欢coding💻、画图🎨、音乐🎵、学习ing~
👋 Social Media
🛠️ Blog: http://oceaneyes.top
⚡ PM导航: https://pmhub.oceangzy.top
☘️ CNBLOG: https://www.cnblogs.com/oceaneyes-gzy/
🌱 AI PRJ自己部署的一些算法demo: http://ai.oceangzy.top/
📫 Email: 1450136519@qq.com
💬 WeChat: OCEANGZY
- 💬 公众号: UncleJoker-GZY
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步