本帖最後由 tonyh 於 2014-11-22 17:05 編輯
產生20組範圍介於1~3之隨機亂數.- public class ch32
- {
- public static void main(String args[])
- {
- for(int i=1; i<=20; i++)
- System.out.println((int)(Math.random()*3+1));
- }
- }
- /*
- Math.random(); 0.00000 ~ 0.99999
- Math.random()*3; 0.00000 ~ 2.99999
- Math.random()*3+1; 1.00000 ~ 3.99999
- (int)(Math.random()*3+1); 1 ~ 3
- */
複製代碼 |