Java基礎之Math類(十)

來源:互聯網
上載者:User

標籤:java;java.lang.math

java.lang.Math提供了一些列靜態方法用於科學計算;其方法的參數和傳回值類型一般為double型。

abs:絕對值;

acos,asin,atan,cos,sin,tan;

sqrt:平方根;

pow(double a,double b)a的b次冪;

log:自然對數

exp:e為底指數

max(double a,double b):取最大值

min(double a,double b):去最小值

random():返回0.0到1.0的隨機數

long round(double a):double型的資料a轉換為long型(四捨五入)

toDegrees(double angrad):弧度轉化為角度

toRadians(double angdeg):角度轉化為弧度

package MyMathClass;

public class Test {

public static void main(String[] args) {

// TODO Auto-generated method stub

double a=Math.random();

double b=Math.random();

System.out.println(Math.sqrt(a*a+b*b));

System.out.println(Math.pow(a, 8));

System.out.println(Math.round(b));

System.out.println(Math.log(Math.pow(Math.E, 15)));

double d=60.0,r=Math.PI/4;

System.out.println(Math.toRadians(d));

System.out.println(Math.toDegrees(r));

System.out.println(Math.E);

System.out.println(Math.PI);

}

}


本文出自 “一步,一步” 部落格,請務必保留此出處http://summerflowers.blog.51cto.com/5202033/1926265

Java基礎之Math類(十)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.