五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊

java Math類和Random類的用法

2022-07-13 20:29 作者:虛云幻仙  | 我要投稿

/**
* 測試Math類的常用方法
* 測試Random類
*/

public class TestMath {
? ?public static void main(String[] args) {
? ? ? ?int a = 4;
? ? ? ?int b = -5;
? ? ? ?int c = 2;
? ? ? ?double d = 1.1;
? ? ? ?double e = 1.5;
? ? ? ?System.out.println(Math.abs(b)+"Math.abs()取絕對值 結(jié)果為5 返回結(jié)果為同數(shù)據(jù)類型");
? ? ? ?System.out.println(Math.sqrt(a)+"Math.sqrt()取平方根 4開平方結(jié)果為2.0 返回double");
? ? ? ?System.out.println(Math.pow(c,a)+"Math.pow()冪運(yùn)算 返回c的a次方 結(jié)果為16.0 返回double");
? ? ? ?System.out.println(Math.max(a,c)+"Math.max()取兩數(shù)最大值 結(jié)果為4 返回同數(shù)據(jù)類型");
? ? ? ?System.out.println(Math.min(a,c)+"Math.min()取兩數(shù)最小值 結(jié)果為2 返回同數(shù)據(jù)類型");
? ? ? ?System.out.println(Math.ceil(d)+"Math.ceil()取大于d的最小整數(shù) 結(jié)果為2.0 返回double");
? ? ? ?System.out.println(Math.floor(e)+"Math.floor()取小于e的最大整數(shù) 結(jié)果為1.0 返回double");
? ? ? ?System.out.println(Math.random()+"取[0,1)的隨機(jī)數(shù) 返回double 范圍包含0不包含1");
? ? ? ?System.out.println(Math.round(e)+"Math.round()四舍五入 結(jié)果為2 返回long");
? ? ? ?System.out.println(Math.toDegrees(Math.PI)+"Math.toDegrees()將弧度轉(zhuǎn)為角度 PI對應(yīng)3.14 結(jié)果為180.0 返回double");
? ? ? ?System.out.println(Math.toRadians(45)+"Math.toRadians()將角度轉(zhuǎn)為弧度 45度等于PI/4 結(jié)果為0.7853981633974483 返回double");
? ? ? ?System.out.println(Math.sin(Math.toRadians(30))+"Math.sin()求弧度的sin值 對邊除以斜邊 用Math.toRadians將30度轉(zhuǎn)換為弧度 結(jié)果為0.49999999999999994 返回double");
? ? ? ?System.out.println(Math.cos(Math.PI/4)+"Math.cos()求弧度的cos值 鄰邊除以斜邊 PI/4是45度 結(jié)果為0.7071067811865476 返回double");
? ? ? ?System.out.println(Math.tan(Math.PI/4)+"Math.tan()求弧度的tan值 對邊除以鄰邊 結(jié)果為0.9999999999999999 返回double");
? ? ? ?System.out.println(Math.toDegrees(Math.asin(0.5))+"Math.asin()求arcsin值 通過已知sin值求弧度 返回double弧度 加toDegrees()轉(zhuǎn)為角度 結(jié)果為30.000000000000004");
? ? ? ?System.out.println(Math.toDegrees(Math.acos(1/Math.sqrt(2)))+"Math.acos()求arccos值 返回double弧度 1除以根號2是45度 結(jié)果為45.00000000000001");
? ? ? ?System.out.println(Math.atan(3.0/4)+"Math.atan()求arctan值 返回double弧度 結(jié)果為0.6435011087932844");

? ? ? ?Random ran = new Random();
? ? ? ?//Random類 用于產(chǎn)生隨機(jī)數(shù)
? ? ? ?System.out.println(ran.nextDouble()+"隨機(jī)生成[0,1)的小數(shù) 作用同Math.random");
? ? ? ?System.out.println(ran.nextInt()+"隨機(jī)生成int值 正負(fù)21億之間隨機(jī)取");
? ? ? ?System.out.println(ran.nextBoolean()+"隨機(jī)生成true或者false");
? ? ? ?System.out.println(ran.nextInt(10)+"隨機(jī)生成[0,10)區(qū)間的整數(shù) 不包含10 隨機(jī)0-9");
? ? ? ?System.out.println(20+ran.nextInt(6)+"隨機(jī)生成20-25的整數(shù) .nextInt(6)是0-5 +20變成20-25");
? ?}
}

java Math類和Random類的用法的評論 (共 條)

分享到微博請遵守國家法律
博乐市| 平利县| 东乡| 新绛县| 凯里市| 桓台县| 平谷区| 德保县| 贵港市| 兴安盟| 富宁县| 阿坝| 陵川县| 宜城市| 黄大仙区| 泽库县| 南乐县| 新和县| 梅河口市| 两当县| 搜索| 武义县| 涪陵区| 巴南区| 雷山县| 崇信县| 阿拉善左旗| 武隆县| 林芝县| 司法| 武夷山市| 大厂| 澎湖县| 白朗县| 城固县| 桂平市| 大名县| 车险| 高邮市| 祁阳县| 肥城市|