挺简单的东西,但是比较实用,减少了很多代码,省得用数组循环 的麻烦
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class test001 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<Integer, Integer> a = new HashMap<Integer, Integer>();
Random b = new Random();
<span style="white-space:pre"> </span>//map用键值对的形式存储,键唯一,如果重复就会进行替换,
while (a.size() < 7) {
int c = b.nextInt(35) + 1;
a.put(c, c);
}
// 打印7个随机数
System.out.println(a);
for (int m : a.keySet()) {
System.out.print(a.get(m) + "\t");
}
}
}