java基礎(五)數學函式

2021-09-24 19:24:24 字數 1229 閱讀 7552

system.out.println(math.todegrees(math.pi/2));//弧度單位化角度

system.out.println(math.toradians(30));//角度單位化弧度

system.out.println(math.sin(math.pi/6));//求sin值

system.out.println(math.cos(math.pi/6));//求cos值

system.out.println(math.asin(math.pi/6));//求反三角函式

system.out.println(math.exp(3.5));system.out.println(math.log(3.5));

system.out.println(math.log10(3.5));

system.out.println(math.pow(2, 3));

system.out.println(math.sqrt(10.5));

system.out.println(math.ceil(2.1));向上取整為它最接近的整數,該整數作為乙個雙精度值返回,此例返回3.0

system.out.println(math.floor(2.1));向下取整為它最接近的整數,該整數作為乙個雙精度值返回,此例返回2.0

system.out.println(math.rint(-2.1));//x取整為它最接近的整數,如果.5距離相等。則返回偶數的那個(-2.0)

system.out.println(math.rint(-2.5));

system.out.println(math.round(2.6f));//如果是單精度數,返回(int)math.floor(x+0.5);如果x是雙精度數,返回(long)math.floor(x+0.5);(3)

system.out.println(math.round(2.5));

system.out.println(math.max(math.max(2.5, 4.6), math.min(3, 5.6)));//此例返回4.6

system.out.println(math.abs(-2.6));//此例返回2.6

在迴圈中,如果使用浮點數大小比較大小作為判斷條件,那麼浮點數涉及的誤差就是不可避免的,因為浮點數在計算機中本身就是近似表示的。所以判斷條件應該盡量選擇整型數。

Java常用數學函式

三角函式方法 sin radians cos radians tan radians toradians degree 將以度為單位的角度值轉化為以弧度表示 todegrees radians 將以弧度為單位的角度值轉化為以度表示 asin a acos a atan a 指數函式方法 exp x ...

數學基礎 隸屬函式

隸屬函式,也稱為歸屬函式或模糊元函式,是模糊集合中會用到的函式,是一般集合中指示函式的一般化。指示函式可以說明乙個集合中的元素是否屬於特定子集合。一元素的指示函式的值可能是0或是1,而一元素的隸屬函式會是0到1之間的數值,表示元素屬於某模糊集合的 真實程度 degree of truth 例如質數為...

JAVA基礎筆記(五)

static 定義不通過物件控制的屬性 static 屬性描述的是公共屬性,回報存在公共資料區裡面 內部類 類中的類 class a 內部類最大的優點 可以方便的訪問外部類的私有屬性,內外部類之間都可以驚醒私有屬性的訪問 不需要getset方法了,檔案中的內部類的class檔案 a b.class ...