小數中一位是「5」時,當個位數是奇數採進位,個位數是偶數將捨去
Math.rint(123.4):123.0
Math.rint(123.5):124.0
Math.rint(124.5):124.0
Math.rint(123.6):124.0
Math.rint(-123.5):-124.0
Math.rint(-124.5):-124.0
random():回傳0.0<=0<1.0的double數值
例.產生1~6的亂數
0.0<=Math.random()<1.0
0.0<=Math.random()*6<6.0
0<=(int)(Math.random()*6)<6
0<=(int)(Math.random()*6)<=5
1<=(int)(Math.random()*6)+1<=6
(int)(Math.random()*6+1)
指定運算-
註:產生1~n的亂數,公式為
(int)(Math.random()*n+1)
沒有留言:
張貼留言