本帖最后由 qetu001212 于 2016-7-13 22:42 编辑
import java.util.ArrayList;
import java.util.Random;
public class GetNumberDemo {
public static void main(String[] args) {
Random r = new Random();
ArrayList<Integer> array = new ArrayList<Integer>();
int count = 0;
while (count < 5) {
int number = r.nextInt(30) + 21;
if(!array.contains(number)) {
array.add(number);
count++;
}
}
for(Integer i : array) {
System.out.println(i);
}
}
}
|