Board logo

標題: 亂數 (三) [打印本頁]

作者: tonyh    時間: 2012-9-29 16:40     標題: 亂數 (三)

本帖最後由 tonyh 於 2012-9-29 16:57 編輯

產生20組範圍介於1~10之整數隨機亂數.
  1. public class ch32
  2. {
  3.   public static void main(String args[])
  4.     {
  5.       for(int i=1; i<=20; i++)
  6.       {
  7.         System.out.println((int)(Math.random()*10+1));    //1~10
  8.       }
  9.     }
  10. }

  11. /*
  12.       System.out.println(Math.random());         //0.0000~0.9999 (無限小數)
  13.       System.out.println(Math.random()*10);       //0.0000~9.9999 (無限小數)
  14.       System.out.println((int)(Math.random()*10));       //0~9
  15.       System.out.println((int)(Math.random()*10+1));       //1~10
  16. */
複製代碼

作者: t2364705    時間: 2012-9-29 16:55

  1. public class ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {

  7.             System.out.println((int)(Math.random()*10+1));
  8.         }
  9.     }
  10. }
複製代碼

作者: 粘靖瑜    時間: 2012-9-29 16:57

  1. public class ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<20; i++)
  6.         {
  7.         System.out.println(Math.random()*10+1);
  8.         }
  9.     }
  10. }
複製代碼

作者: 尤泓鈞    時間: 2012-9-29 16:58

  1. public class ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {

  7.             System.out.println((int)(Math.random()*10+1));
  8.         }
  9.     }
  10. }
複製代碼

作者: 劉漢文    時間: 2012-9-29 16:59

  1. public class ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {

  7.             System.out.println((int)(Math.random()*10+1));
  8.         }
  9.     }
  10. }
複製代碼

作者: t3742238    時間: 2012-9-29 17:00

  1. public class ch28
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)

  6.         {

  7.             System.out.println((int)(Math.random()*10+1));
  8.         }


  9.     }
  10. }
複製代碼

作者: 蔡昀佑    時間: 2012-9-29 17:03

  1. public class ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {

  7.             System.out.println((int)(Math.random()*10+1));
  8.         }
  9.     }
  10. }
複製代碼

作者: 粘靖瑜    時間: 2012-9-29 17:08

  1. public class ch33
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<20; i++)
  6.         {
  7.         System.out.println(Math.random()*5+123);
  8.         }
  9.     }
  10. }
複製代碼

作者: 黃博鴻    時間: 2012-10-27 15:21

  1. public class ch31
  2. {
  3.    public static void main(String args[])
  4.    {
  5.      for(int i=1; i<=20; i++)
  6.      {
  7.         System.out.println((int)(Math.random()*10+1));
  8.      }
  9.    }
  10. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2