JAVA學習筆記
2013年1月2日 星期三
JAVA如何產生隨機的整數
這裡我們使用到API中 Math Class的random()方法
詳細的語法如下
int a = (int)( Math.random() * 10);
其中 Math.random() 會產生一個小於0的浮點數
我們將他乘以十之後再轉換成 int 型態
便可以得到 0 ~ 9 的隨機整數
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言