50位的隨機數(shù)怎么生成?
//測試通過,見代碼實現(xiàn)
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class RandomTestA {
public static void main(String[] args) {
Random r = new Random();
float sum=0;
List list=new ArrayList();
for (int i = 0; i < 100; i++) {
float a=r.nextFloat()*100;
list.add(a);
}
Collections.sort(list);
for (int i = 0; i < list.size(); i++) {
sum+=(Float) list.get(i);
}
System.out.println("和="+sum);
System.out.println("平均值="+(sum/100));
System.out.println("最小值="+list.get(0));
}
}
上一篇怎么輸出