返回列表 發帖

亂數 (二)

本帖最後由 tonyh 於 2016-5-6 20:21 編輯

運用 random() 函式搭配for迴圈,
產生20組範圍介於0.00000~0.99999之隨機亂數.
  1. public class Ch31
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.             System.out.println(Math.random());
  7.     }
  8. }
複製代碼

本帖最後由 王翔 於 2016-5-7 16:09 編輯
  1. public class Ch27
  2. {
  3.     public static void main(String args[])
  4.     {

  5.         for(int i=1;i<=20;i++)
  6.         {
  7.                 System.out.println(Math.random());
  8.         }

  9.     }
  10. }
複製代碼

TOP

  1. public class Ch34
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         double r;
  6.         for(int i=0; i<=19; i++)
  7.         {
  8.             
  9.             r=Math.random();
  10.             System.out.print(r);
  11.         }

  12.     }
  13. }
複製代碼

TOP

  1. public class Ch35
  2. {
  3.     public static void main(String args[])
  4.     {

  5.         for(int i=1;i<=20;i++)
  6.         System.out.println(Math.random());

  7.     }
  8. }
複製代碼

TOP

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

TOP

  1. public class Ch34
  2. {
  3.     public static void main(String args[])
  4.     {
  5.              for(int i=1;i<=20;i++)
  6.                 System.out.println(Math.random());

  7.     }
  8. }
複製代碼

TOP

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

TOP

本帖最後由 曾挺桂 於 2016-5-6 20:10 編輯
  1. public class Ch30
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.         {        
  7.             double x=Math.random();
  8.             System.out.println(x);
  9.         }   
  10.     }
  11. }
複製代碼

TOP

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

TOP

本帖最後由 梁和雋 於 2016-5-6 20:00 編輯
  1. public class Ch30
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1;i<=20;i++)
  6.             System.out.println(Math.random());
  7.     }
  8. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

返回列表