返回列表 發帖

亂數 (三)

產生20組範圍介於1~3之隨機亂數(整數).
  1. public class Ch32
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         for(int i=1; i<=20; i++)
  6.             System.out.println((int)(Math.random()*3+1));
  7.     }
  8. }
  9. /*
  10.   Math.random()             0.0000 ~ 0.999999
  11.   Math.random()*3           0.0000 ~ 2.999999
  12.   Math.random()*3+1         1.0000 ~ 3.999999
  13.   (int)(Math.random()*3+1)  1 ~ 3
  14. */
複製代碼

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

TOP

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

TOP

  1. public class Ch02
  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()*3+1));
  8.         }
  9.     }
  10. }
複製代碼
:))))))))))))))

TOP

  1. public class Ch01 {
  2.         public static void main(String[] args) {
  3.                 for(int i=1; i<=20; i++)
  4.                 {
  5.                         System.out.println((int)(Math.random()*3+1));
  6.                 }
  7.         }
  8. }
複製代碼
巨槌瑞斯!!!誇爪!!!哈哈哈哈!!!
還敢下來阿冰鳥

TOP

  1. import java.util.Scanner;

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

TOP

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

TOP

  1. public class CH01
  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()*3+1));
  8.             }
  9.     }
  10. }
複製代碼

TOP

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

TOP

  1. import java.util.Scanner;


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

TOP

  1. public class Ch01 {

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

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

TOP

返回列表