朋友们 帮帮忙 用JAVA随机生成10个100以内的整数并按从小到大的顺序排列 感激不尽

2024-12-26 06:16:03
推荐回答(1个)
回答1:

import java.util.Iterator;
import java.util.SortedSet;
import java.util.TreeSet;

/**

/**
* @ClassName: Random
* @Description: TODO
* @author :
* @date May 24, 2012 9:30:49 AM
*
*/
public class Random {

/**
* @Title: main
* @Description: TODO
* @param args
* @return void
* @throws
*/
public static void main(String[] args) {
String random[] = new String[10];
for(int i=0;i int a = (int)(Math.random()*100);
random[i]=a+"";
System.out.println("random["+i+"]= "+random[i]);
}

SortedSet ts=new TreeSet();
for(int j=0; j ts.add(random[j]);
}

Iterator it = ts.iterator();
while(it.hasNext()){
String s = (String) it.next();
System.out.print(s+",");
}

}

}