新聞中心
大家好,我是Java進(jìn)階者,今天小編帶大家一起來(lái)學(xué)習(xí)Java技術(shù)基礎(chǔ)!

10年的漳州網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都營(yíng)銷網(wǎng)站建設(shè)的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整漳州建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“漳州網(wǎng)站設(shè)計(jì)”,“漳州網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
一、Math類取整函數(shù)方法
1.Math類取整函數(shù)方法,如下所示:
public static double ceil(double a)方法:返回double類值的最小值,這個(gè)值大于或等于。簡(jiǎn)單來(lái)說(shuō)是向上取整;
public static double floor(double a)方法:返回double類值的最大值,這個(gè)值小于或等于。簡(jiǎn)單來(lái)說(shuō)是向下取整;
public static double rint(double a)方法:返回最接近的參數(shù)a的值,并且它的值是double類型的值;
public static int round(float a)方法:返回最接近的參數(shù)加上0.5將結(jié)果轉(zhuǎn)換為int類型,也就是四舍五入取整;
public static long round(double a)方法:返回最接近的參數(shù)加上0.5將結(jié)果轉(zhuǎn)換為long類型,也就是四舍五入取整;
2.Math類取整函數(shù)方法例子:
- 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));
- }
- }
運(yùn)行的結(jié)果是:
二、Math類三角函數(shù)方法
1.Math類三角函數(shù)方法,如下所示:
public static double sin(double a)方法:返回參數(shù)的正弦值,a是以弧度表示角度;
public static double cos(double a)方法:返回參數(shù)的余弦值,a是以弧度表示角度;
public static double tan(double a)方法:返回參數(shù)的正切值,a是以弧度表示角度;
public static double asin(double a)方法:返回參數(shù)的反正弦值;
public static double acos(double a)方法:返回參數(shù)的反余弦值;
public static double atan(double a)方法:返回參數(shù)的反正切值;
public static double toRadians(double a) : 把角度轉(zhuǎn)換為弧度;
public static doueble toDegrees(double a) : 把弧度轉(zhuǎn)化為角度;
2.Math類三角函數(shù)方法例子
- 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));
- }
- }
運(yùn)行的結(jié)果是:
三、Math類指數(shù)函數(shù)方法
1.Math類指數(shù)函數(shù)方法,如下所示:
public static double sqrt(double a ):用來(lái)取a的平方根(a2);
public static double cbrt(double a ):用來(lái)取a的立方根(a3);
public static double log(double a ):相當(dāng)于lna;
public static double log10(double a ):以10為底的對(duì)數(shù),也就是log10a;
public static double exp(double a ):用來(lái)獲取e的a次方;
public static double pow(double a,double b):a表示底數(shù),b表示指數(shù),用來(lái)求a的b次方;
2.Math類指數(shù)函數(shù)方法例子:
- 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的對(duì)數(shù):"+Math.log10(10));
- }
- }
運(yùn)行的結(jié)果是:
四、總結(jié)
本文主要介紹了Math類取整函數(shù)方法、三角函數(shù)方法、指數(shù)函數(shù)方法。
Math類取整函數(shù)方法有ceil、floor、rint、round,這些方法通過(guò)例子了解它的用法。Math類三角函數(shù)方法有sin、cos、tan、toRadians、toDegrees等,這些方法通過(guò)例子了解它的用法。
Math類指數(shù)函數(shù)方法有sqrt、cbrt、log、log10等,這些方法通過(guò)例子了解它的用法。希望大家通過(guò)本文的學(xué)習(xí),對(duì)你有所幫助!
本文轉(zhuǎn)載自微信公眾號(hào)「Java進(jìn)階學(xué)習(xí)交流」,作者Java進(jìn)階者。轉(zhuǎn)載本文請(qǐng)聯(lián)系Java進(jìn)階學(xué)習(xí)交流公眾號(hào)。
網(wǎng)頁(yè)標(biāo)題:盤點(diǎn)Math類中取整函數(shù)、三角函數(shù)和指數(shù)函數(shù)方法
本文網(wǎng)址:http://www.dlmjj.cn/article/dpsgeio.html


咨詢
建站咨詢
