




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、例如求平方根的Math.sqrt(n),求a的b次方Math.pow(a, b),求绝对值Math.abs(n)等很多。下面是一些演示。public class MathTest public static void main(String args) int n = 16;
2、; System.out.println(Math.sqrt(n); System.out.println(Math.pow(2, 3); System.out.println(Math.abs(-4); System.out.println(Math.log1
3、0(100); public class MathDemo public static void main(String args) /* * abs求绝对值
4、0; */ System.out.println(Math.abs(-10.4); /10.4 System.out.println(Math.abs(10.1); /10.1 &
5、#160; /* * ceil天花板的意思,就是返回大的值,注意一些特殊值 */ System.out.println(Math.ceil(-10.1); /-10.0
6、 System.out.println(Math.ceil(10.7); /11.0 System.out.println(Math.ceil(-0.7); /-0.0 System.out.println(Math.ceil(0.0);
7、 /0.0 System.out.println(Math.ceil(-0.0); /-0.0 /* * floor地板的意思,就是返回小的值 &
8、#160; */ System.out.println(Math.floor(-10.1); /-11.0 System.out.println(Math.floor(10.7); /10.0
9、; System.out.println(Math.floor(-0.7); /-1.01 / 7 System.out.println(Math.floor(0.0); /0.0 System.out.println(Math.floor(-0.0); /-0.
10、0 /* * max 两个中返回大的值,min和它相反,就不举例了 */ System.out.println(Math.max(-10.1, -10);
11、160; /-10.0 System.out.println(Math.max(10.7, 10); /10.7 System.out.println(Math.max(0.0, -0.0); /0.0
12、160; /* * random 取得一个大于或者等于0.0小于不等于1.0的随机数 */ System.out.println(Math.random(); /0.08
13、417657924317234 System.out.println(Math.random(); /0.43527904004403717 /* * rint 四舍五入,返回double值 &
14、#160; * 注意.5的时候会取偶数 */ System.out.println(Math.rint(10.1); /10.0 System.out.println(Math.rint(10.7);
15、160; /11.0 System.out.println(Math.rint(11.5); /12.0 System.out.println(Math.rint(10.5); /10.0 S
16、ystem.out.println(Math.rint(10.51); /11.0 System.out.println(Math.rint(-10.5); /-10.0 System.out.println(Math.rint(-11.5); /-12.0
17、160; System.out.println(Math.rint(-10.51); /-11.0 System.out.println(Math.rint(-10.6); /-11.0 System.out.println(Math.rint(-1
18、0.2); /-10.0 /* * round 四舍五入,float时返回int值,double时返回long值 */ System.
19、out.println(Math.round(10.1); /10 System.out.println(Math.round(10.7); /11 System.out.println(Math.round(10.5); /11
20、0; System.out.println(Math.round(10.51); /11 System.out.println(Math.round(-10.5); /-10 System.out.println(Math.round(-10.51);
21、; /-11 System.out.println(Math.round(-10.6); /-11 System.out.println(Math.round(-10.2); /-10 函数(方法)描述IEEEremainder(double,
22、0;double)按照 IEEE 754 标准的规定,对两个参数进行余数运算。abs(int a)返回 int 值的绝对值abs(long a)返回 long 值的绝对值abs(float a)返回 float 值的绝对值abs(double a)返回 double 值的绝对值acos(double a)返回角的反余弦,范围在 0.0 到 pi 之间asin(double a)返回角的反
23、正弦,范围在 -pi/2 到 pi/2 之间atan(double a)返回角的反正切,范围在 -pi/2 到 pi/2 之间atan2(double a, double b)将矩形坐标 (x, y) 转换成极坐标 (r, theta)ceil(double a)返回最小的(最接近负无穷大)double 值,该值大于或等于参数,并且等于某个整数cos(double)返回角的三角余弦exp(double
24、60;a)返回欧拉数 e 的 double 次幂的值floor(double a)返回最大的(最接近正无穷大)double 值,该值小于或等于参数,并且等于某个整数log(double a)返回(底数是 e)double 值的自然对数max(int a, int b)返回两个 int 值中较大的一个max(long a, long b)返回两个 long 值中较大的一个max(float a,
25、160;float b)返回两个 float 值中较大的一个max(double a, double b)返回两个 double 值中较大的一个min(int a, int b)返回两个 int 值中较小的一个min(long a, long b)返回两个 long 值中较小的一个min(float a, float b)返回两个 float 值中较小的一个min(d
26、ouble a, double b)返回两个 double 值中较小的一个pow(double a, double b)返回第一个参数的第二个参数次幂的值random()返回带正号的 double 值,大于或等于 0.0,小于 1.0rint(double)返回其值最接近参数并且是整数的 double 值round(float)返回最接近参数的 intround(double)返回最接近参数的 longsin(double)返回角的三角
27、正弦sqrt(double)返回正确舍入的 double 值的正平方根tan(double)返回角的三角正切toDegrees(double)将用弧度测量的角转换为近似相等的用度数测量的角toRadians(double)将用度数测量的角转换为近似相等的用弧度测量的角可以看出,Math类提供了我们数学计算中常用的方法,使用它们可以完成大部分的数学计算操作。下面我们来试试几个例子:又要出现大家之前经常见到的MainClass了,下面给大家大致展示下Math类的使用,如下代码: Java代码/* · *
28、;类功能描述 * MainClass.java · * * author zhangtao · * version 0.1.0 */ · public class MainClass
29、60; · /* * param args · */ public static void main(String args)
30、60; · double loanAmount = 0; double top = 2 * 5 / 1200; ·
31、; double bot = 1 - Math.exp(5 * (-12) * Math.log(1 + 7 / 1200); · System.out.println(loanAmount);
32、60; System.out.println(top); · System.out.println(bot); · 上述代码展示了Math类的使用,代码我就不细说了。
33、这里大家需要注意的是Math类的方法为静态提供的,即,我们可以不用使用new关键字实例化Math类而直接使用它的方法。查找float、int、double数的绝对值在我们之前给出的方法列表中,我们知道Math类可以计算数字的绝对值,下面给出一个例子,来演示下abs方法的使用。abs是absolute的缩写,absolute是绝对的意思。下面是例子:Java代码/* · * 类功能描述 * MainClass.java ·
34、; * * author zhangtao · * version 0.1.0 */ · public class MainClass · /*
35、160; * param args · */ public static void main(String args) · int i
36、 = 8; int j = -5; · System.out.println("Absolute value of " + i + " is
37、60;:" + Math.abs(i); System.out.println("Absolute value of " + j + " is :" + Math.abs(j); · &
38、#160; float f1 = 1.40f; · float f2 = -5.28f; System.out.println("Absolute
39、0;value of " + f1 + " is :" + Math.abs(f1); · System.out.println("Absolute value of " + f2 + " is :" + Math.abs(f2); · double d1 = 3.324; double d2 =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 弹弓指 的护理及运动
- 2025至2030巴基斯坦基础建设行业产业运行态势及投资规划深度研究报告
- 商业综合体的安全管理及风险控制策略研究报告
- 中药与肠道微生态的关联研究
- 2025至2030维生素口嚼片行业项目调研及市场前景预测评估报告
- 2025至2030中国自由飞行服行业市场占有率及投资前景评估规划报告
- 2025至2030中国自动装配机行业产业运行态势及投资规划深度研究报告
- 2025至2030中国自主无人机无线充电和基础设施行业市场占有率及投资前景评估规划报告
- 2025至2030中国腕式潜水电脑行业发展趋势分析与未来投资战略咨询研究报告
- 2025至2030中国能源行业市场发展分析及投资前景与投资策略报告
- 生物膜技术革新:MBBR与IFAS工艺中功能性生物膜挂膜驯化的深入探讨
- 心肺复苏课件
- 2025至2030全球及中国企业文件共享和同步(EFSS)行业产业运行态势及投资规划深度研究报告
- 上海金山区属国有企业招聘笔试真题2024
- 2025至2030中国碳化硅陶瓷膜行业发展趋势分析与未来投资战略咨询研究报告
- 金属与石材幕墙工程技术规范-JGJ133-2013含条文说
- 电网公司项目管理标准手册
- 卫生值日表格源码文件可编辑可修改
- ASTM B344-20 电加热元件用拉制或轧制镍铬及镍铬铁合金标准规范
- 《石油化工企业储运罐区罐顶油气连通安全技术要求》
- 人教版七年级数学下册计算类专项训练卷【含答案】
评论
0/150
提交评论