Random类

 1 package Format_daqo;
 2 
 3 import java.util.Arrays;
 4 import java.util.Random;
 5 
 6 public class Randoms {
 7 
 8     public static void main(String[] args) {
 9         int[] score =new int[100];
10         //取100个0到100之间的随机数
11         for (int i = 0; i < score.length; i++) {
12             score[i]=(int)(Math.random()*101);
13         }
14         System.out.println(Arrays.toString(score));
15         //查找100分的或0分的
16         for (int i = 0; i < score.length; i++) {
17             if(score[i]==0||score[i]==100){
18                 System.out.println(i+"\t"+score[i]);
19             }
20         }
21         
22         System.out.println("-----------------");
23         
24         //Random
25         Random rand=new Random();
26         double[] arr=new double[50];
27         for (int i = 0; i < arr.length; i++) {
28             arr[i]=rand.nextDouble()*100;
29         }
30         System.out.println(Arrays.toString(arr));
31     }
32     
33 }

 

posted @ 2016-09-22 13:26  奋斗的少年WH  阅读(117)  评论(0编辑  收藏  举报