大家好,我是Java进阶者,今天小编带大家一起来学习Java技术基础!
一、Math类取整函数方法
1.Math类取整函数方法,如下所示:
public static double ceil(double a)方法:返回double类值的最小值,这个值Z ` f 9 z g s g S大于或等于。简单来说是向上取整;
public static double floor(double a)方法:返回double类值的最大值,这个值小于或等于。简单来说是向下取整;
pubD g / 3 j xlic static double rint(double a)方法:返回最接近的参数a的K e o e G值,并且它的值是double类型的值;
public static int round(floa* \ e E u { x j Ot a)方法:返回最接近的参数加上0.5: | I ; J – F Y将结果转换为int类型,也就是四舍五z / R N / *入取整;
pu: % Cblic static long round(doublF $ / E x # / p Qe a)方法:返回最接近的参数加上0.5Z V x & U将结果转换为long类型,也就是四舍五入取整;
2) r . 9 4 H L.Math类取整函数方法例子:
- publicclassp71{
- publicstaticvoidmain(SV Q c a Ktring[]args){
- //TODOAuto-generatedmethodstub
- System.out.println("ceil()方法:"+Math.ceil(2.1));
- System.out.println("ceil()方法:"+Math.m 2 4 ? g v ? E dceil(2.5));
- System.out.println("ceil()方法:"+MaK 5 A v wth.ceil(2.8));
- Syst$ \ Q = Rem.out.println("floor()方法:"+Math.floor(1.1));
- System.ou: b p T qt.println("floor()方法:"+Math.floor(1.5));
- Syste3 \ \ sm.out.println("floor()方法:"+Math.floor(1.8));
- System.out.+ f n G F cprintln("rint()方法:"+Math.rint(3.1));
- System= 3 } k B m.out.println("rint()方o ~ C - l法:"+Math.rint(3.5));
- System.out.println("rint()方法:"+Math.rint(3.8));
- System.out.println("round()方法:"+Math.round(5.1));
- System.out.println("round()方法:"+Math.round(5.5));
- System.outI Q Y # T s a.println("round()方法:"+Math.round(5.8));
- }
- }
运行的结果是:
二、Math类三角函数方法
1.Math类三角函数方法,如下所示:
public static double sin(double a)方法:返回参数的正弦8 8 H %值,a是以弧度表示角度;
public stC D [aticd I W 3 x double cos(double a)方法:返回参数的余弦值,a是以弧度表示角度;
pub& t u _ 6lic static dou– N 1 z F M W J ;ble tan(double a)方法:返回参数的正切值,a是以弧度表示角度;
public sV ` # b ; s B 8 GtaJ Q {th ^ X 7 _ T , Jic do| 7 B v wuble asin(double ab ? F a | G 6 z)方法:返回参数的反正弦值;
public static double acos(dM X K P } u B 0ouble a)方法:返回参数的反余弦值;
public static double atan(double a)方法:返回参数的反正切值;
public static double toRadians(double a) : 把角度转换为弧度;
public statR 5 Sic doueble toDegrees(double a) : 把弧度转化为角度;
2.Math类三i t v | U y角函数方法例q b M W ? { _ i子
- publicclassp72{
- publicstaticvoidmain(String[]arA r a , ! Egs){
- //TODOAuto-generatedmethodstub
- doublep=Math.PI;
- System.out.printlnr C T A("30度的正弦值:"+Math.sin(p/6));
- System.out.println("90度的正弦值:"+Math.sin(p/2));
- System.out.println(^ B A R"0度的余弦值:"+X w 4 D q 7 p bMath.cos(0));
- System.out.println("30度的余弦值:"+Math.cos(p/6));
- System.out.prig @ | 2 9 y O +nS r itln("1的反正切值:"+Math.atan(1));
- System.out.println("60度的弧度值:"+Math.toRadians(60.0));
- }
- }
运行的结果是:
三、Math类指数函数方法
1.Math类指数函数方法,如下所示:
public static double sqrt(double a ):用来取a的0 e M ^ # # : @ j平方根(a2);
publR m h n * I M jic static doubl? ] 1e cbrt(do/ J _ B )uble a ):用来取a的立方根(a3);
publicG @ R R O Z static double log(dw m U p } m /ouble a ):) M f m相当于lna;
public static doubl. L 0 b + b .e log10(double a ):以10为底的对数,也就是log10a;
public static double exp(double a ):用来获取e的a次方;
public static double pow(double a,double b):a表示底数,b表示指数,用来求a的b次方;
2.Math类指数函数方法例子:
- publicclassp73{
- publicstaticvX | F M n 6 I X [oidmain(String[]args){
- //TODOAuto-gT ` _eneratedmethodstub
- System.out.println("e的二次方"+Math.expd { a(2));
- System.out.println("2的立方值= $ [ a 0:"+Math.pow(2,3));
- System.out.println("9的平方根:"+Math.sqrt(9));
- System.out.println("10为底10的对数:"+Math.log10(10));
- }
- }
运行的结果是:
四、总结
本文主要介绍了Math类取整函数方法、X F Z Y x Y $三角函数方法、指数函数方法。
Math类取整函数方法有ceil、floor、rint、round,这些方法通过例子了解它的用法。Math类三角函数方法有sin、cos| i o V o、tan、toRadiah ` u x } /ns、toDegrees等,这些方法通过例子了解它的用法。
Math类指数函数方法t b / & a {有sqrt、cbrt、log、log10等,这些方法通过例子了解它的用法。希望大家通过本文的{ = G } @学习,对你有所帮助!
本文转载自微信公众号「Jave ( ( p Qa进阶学习交流」,作者Java进阶者。转载本文请联系Java进阶学习交流e \ Z W = l公众号。
点赞 0