<%
ArrayList ary = new ArrayList();
Random rand = new Random();
for (int j=0;j<99;j++) {
int i = rand.nextInt(99);
ary.add(new Integer(i));
out.print(ary.get(j)+".");
}
%>
上面能打印出99个随机数字来,但是我想打出99个不同的随机数,该怎么做?而且最后我还想把打印出来的remove掉,把剩下的打印出来,该怎么做啊?
------解决方案--------------------
- Java code
ArrayList ary = new ArrayList(); Random rand = new Random(); while (ary.size() < 99) { int i = rand.nextInt(99); if (ary.contains(i)) { continue; } ary.add(i); out.print(i + "."); }
------解决方案--------------------
3楼说的对,楼主没有把问题说清楚。