java之數學方法--未完成

來源:互聯網
上載者:User

標籤:pac   參考   code   static   http   void   float   pow   ati   

參考http://how2j.cn/k/number-string/number-string-math/319.html

java.lang.Math提供了一些常用的數學運算方法,並且都是以靜態方法的形式存在

四捨五入, 隨機數,開方,次方,π,自然常數
package digit;  public class TestNumber {      public static void main(String[] args) {        float f1 = 5.4f;        float f2 = 5.5f;        //5.4四捨五入即5        System.out.println(Math.round(f1));        //5.5四捨五入即6        System.out.println(Math.round(f2));                 //得到一個0-1之間的隨機浮點數(取不到1)        System.out.println(Math.random());                 //得到一個0-10之間的隨機整數 (取不到10)        System.out.println((int)( Math.random()*10));        //開方;先對9開方,然後轉成int類型        System.out.println(Math.sqrt(9));
     //例如,(int)Math.sqrt(2)=(int)1.414=1
//次方(2的4次方) System.out.println(Math.pow(2,4)); //π System.out.println(Math.PI); //自然常數 System.out.println(Math.E);

 

      Math.abs();取絕對值

      Math.floor();向上取整

      Math.ceil();向下取整
    }}
練習-質數

 

java之數學方法--未完成

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.