当前位置:首页 > IT科技类资讯

盘点Math类中取整函数、三角函数和指数函数方法

大家好,盘点我是类中Java进阶者,今天小编带大家一起来学习Java技术基础!

一、取整Math类取整函数方法

1.Math类取整函数方法,函数函数如下所示:

public static double ceil(double a)方法:返回double类值的角函最小值,这个值大于或等于。数和简单来说是指数向上取整;

public static double floor(double a)方法:返回double类值的最大值,这个值小于或等于。盘点简单来说是类中向下取整;

public static double rint(double a)方法:返回最接近的参数a的值,并且它的取整值是double类型的值;

public static int round(float a)方法:返回最接近的参数加上0.5将结果转换为int类型,也就是函数函数四舍五入取整;

public static long round(double a)方法:返回最接近的参数加上0.5将结果转换为long类型,也就是角函四舍五入取整;

2.Math类取整函数方法例子:

public class p71 {  public static void main(String[] args) {          // TODO Auto-generated method stub         System.out.println("ceil()方法 :"+Math.ceil(2.1));         System.out.println("ceil()方法 :"+Math.ceil(2.5));         System.out.println("ceil()方法 :"+Math.ceil(2.8));         System.out.println("floor()方法 :"+Math.floor(1.1));         System.out.println("floor()方法 :"+Math.floor(1.5));         System.out.println("floor()方法 :"+Math.floor(1.8));         System.out.println("rint()方法 :"+Math.rint(3.1));         System.out.println("rint()方法 :"+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.out.println("round()方法 :"+Math.round(5.8));   } } 

运行的结果是:

二、Math类三角函数方法

1.Math类三角函数方法,数和如下所示:

public static double sin(double a)方法:返回参数的指数正弦值,a是源码下载盘点以弧度表示角度;

public static double cos(double a)方法:返回参数的余弦值,a是以弧度表示角度;

public static double tan(double a)方法:返回参数的正切值,a是以弧度表示角度;

public static double asin(double a)方法:返回参数的反正弦值;

public static double acos(double a)方法:返回参数的反余弦值;

public static double atan(double a)方法:返回参数的反正切值;

public static double toRadians(double a) : 把角度转换为弧度;

public static doueble toDegrees(double a) : 把弧度转化为角度;

2.Math类三角函数方法例子

public class p72 {  public static void main(String[] args) {          // TODO Auto-generated method stub         double p=Math.PI;         System.out.println("30度的正弦值:"+Math.sin(p/6));         System.out.println("90度的正弦值:"+Math.sin(p/2));         System.out.println("0度的余弦值:"+Math.cos(0));         System.out.println("30度的余弦值:"+Math.cos(p/6));         System.out.println("1的反正切值:"+Math.atan(1));         System.out.println("60度的弧度值:" + Math.toRadians(60.0));     } } 

运行的结果是:

三、Math类指数函数方法

1.Math类指数函数方法,如下所示:

public static double sqrt(double a ):用来取a的平方根(a2);

public static double cbrt(double a ):用来取a的立方根(a3);

public static double log(double a ):相当于lna;

public static double 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类指数函数方法例子:

public class p73 {  public static void main(String[] args) {          // TODO Auto-generated method stub         System.out.println("e的二次方"+Math.exp(2));         System.out.println("2的立方值:"+Math.pow(2, 3));         System.out.println("9的网站模板平方根:"+Math.sqrt(9));         System.out.println("10为底 10的对数:"+Math.log10(10));   } } 

运行的结果是:

四、总结

本文主要介绍了Math类取整函数方法、三角函数方法、指数函数方法。

Math类取整函数方法有ceil、floor、rint、round,这些方法通过例子了解它的用法。Math类三角函数方法有sin、cos、tan、toRadians、toDegrees等,这些方法通过例子了解它的用法。

Math类指数函数方法有sqrt、cbrt、log、log10等,这些方法通过例子了解它的用法。希望大家通过本文的学习,对你有所帮助!

本文转载自微信公众号「Java进阶学习交流」,作者Java进阶者。转载本文请联系Java进阶学习交流公众号。亿华云计算

分享到:

滇ICP备2023006006号-16