成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Java中Math類常用方法代碼詳解

近期用到四舍五入想到以前整理了一點,就順便重新整理好經(jīng)常見到的一些四舍五入,后續(xù)遇到常用也會直接在這篇文章更新。。。

我們注重客戶提出的每個要求,我們充分考慮每一個細(xì)節(jié),我們積極的做好成都做網(wǎng)站、成都網(wǎng)站設(shè)計服務(wù),我們努力開拓更好的視野,通過不懈的努力,成都創(chuàng)新互聯(lián)公司贏得了業(yè)內(nèi)的良好聲譽(yù),這一切,也不斷的激勵著我們更好的服務(wù)客戶。 主要業(yè)務(wù):網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)站設(shè)計,小程序設(shè)計,網(wǎng)站開發(fā),技術(shù)開發(fā)實力,DIV+CSS,PHP及ASP,ASP.Net,SQL數(shù)據(jù)庫的技術(shù)開發(fā)工程師。

public class Demo{
  public static void main(String args[]){ 
    /** 
     *Math.sqrt()//計算平方根
     *Math.cbrt()//計算立方根
     *Math.pow(a, b)//計算a的b次方
     *Math.max( , );//計算最大值
     *Math.min( , );//計算最小值
     */ 
    System.out.println(Math.sqrt(16));  //4.0 
    System.out.println(Math.cbrt(8));  //2.0
    System.out.println(Math.pow(3,2));   //9.0
    System.out.println(Math.max(2.3,4.5));//4.5
    System.out.println(Math.min(2.3,4.5));//2.3
    /** 
     * abs求絕對值 
     */ 
    System.out.println(Math.abs(-10.4));  //10.4 
    System.out.println(Math.abs(10.1));   //10.1 
    /** 
     * ceil天花板的意思,就是返回大的值
     */ 
    System.out.println(Math.ceil(-10.1));  //-10.0 
    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));   //0.0 
    System.out.println(Math.ceil(-0.0));  //-0.0 
    System.out.println(Math.ceil(-1.7));  //-1.0
    /** 
     * floor地板的意思,就是返回小的值 
     */ 
    System.out.println(Math.floor(-10.1)); //-11.0 
    System.out.println(Math.floor(10.7));  //10.0 
    System.out.println(Math.floor(-0.7));  //-1.0 
    System.out.println(Math.floor(0.0));  //0.0 
    System.out.println(Math.floor(-0.0));  //-0.0 
    /** 
     * random 取得一個大于或者等于0.0小于不等于1.0的隨機(jī)數(shù) 
     */ 
    System.out.println(Math.random()); //小于1大于0的double類型的數(shù)
    System.out.println(Math.random()*2);//大于0小于1的double類型的數(shù)
    System.out.println(Math.random()*2+1);//大于1小于2的double類型的數(shù)
    /** 
     * rint 四舍五入,返回double值 
     * 注意.5的時候會取偶數(shù)  異常的尷尬=。=
     */ 
    System.out.println(Math.rint(10.1));  //10.0 
    System.out.println(Math.rint(10.7));  //11.0 
    System.out.println(Math.rint(11.5));  //12.0 
    System.out.println(Math.rint(10.5));  //10.0 
    System.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 
    System.out.println(Math.rint(-10.51)); //-11.0 
    System.out.println(Math.rint(-10.6));  //-11.0 
    System.out.println(Math.rint(-10.2));  //-10.0 
    /** 
     * round 四舍五入,float時返回int值,double時返回long值 
     */ 
    System.out.println(Math.round(10.1));  //10 
    System.out.println(Math.round(10.7));  //11 
    System.out.println(Math.round(10.5));  //11 
    System.out.println(Math.round(10.51)); //11 
    System.out.println(Math.round(-10.5)); //-10 
    System.out.println(Math.round(-10.51)); //-11 
    System.out.println(Math.round(-10.6)); //-11 
    System.out.println(Math.round(-10.2)); //-10 
  } 
}

總結(jié)

以上所述是小編給大家介紹的Java中Math類常用方法代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留

言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!

標(biāo)題名稱:Java中Math類常用方法代碼詳解
瀏覽路徑:http://jinyejixie.com/article6/pddgig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、云服務(wù)器服務(wù)器托管、做網(wǎng)站網(wǎng)站維護(hù)、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)
永康市| 长乐市| 凤山市| 东丽区| 大余县| 江安县| 兴海县| 云梦县| 金湖县| 佳木斯市| 广水市| 驻马店市| 万载县| 冀州市| 武隆县| 固阳县| 南雄市| 克拉玛依市| 泾川县| 莲花县| 周宁县| 道孚县| 临高县| 焉耆| 磴口县| 徐州市| 大悟县| 临夏县| 三门县| 桃源县| 浪卡子县| 山阴县| 霍城县| 房产| 长白| 中西区| 临泽县| 湟中县| 乐昌市| 土默特左旗| 襄垣县|