第1个回答 2015-10-23
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class RandomTest {
public static void main(String[] args) {
List<Integer> resultList = new ArrayList<Integer>();
Random r = new Random();
while (true) {
int num = r.nextInt(23) + 1;
if (!resultList.contains(num))
resultList.add(num);
if (resultList.size() >= 5)
break;
}
System.out.println(resultList);
}
}本回答被网友采纳