1.题目:
2.思路:(1)掌握random函数实现产生随机数的方法
(2)应用 TreeSet实现类中添加的元素是从小到大并且Set中无重复的性质
3.源代码:
package com.fan.homework1;
import java.util.Random;
import java.util.TreeSet;
import java.util.Set;
public class sortnum {
public static void main(String[] args)
{
int[] RandomNum = new int[1000];
for(int i = 0; i < 1000; i++)
{
RandomNum[i] = (int)(Math.random()*100);
}
//生成20个0~99的随机整数
System.out.printf("随机产生的数据为:");
for(Integer a : RandomNum)
{
System.out.printf(a+" ");
}
System.out.printf("\n");
TreeSet<Integer> MyTreeSet = new TreeSet<Integer>();
for(Integer a : RandomNum)