|

楼主 |
发表于 2020-4-23 13:25:39
|
显示全部楼层
- package per.whj.zwks.ch01;
- import java.util.*;
- public class Text6 {
- public static void main(String[] args) {
- Random r = new Random();
- List list = new ArrayList<HashSet>();
- for (int i = 0; i < 100; i++) {
- Set set = new HashSet<Integer>();
- int j = 0;
- while (j < 7) {
- int random = r.nextInt(37);
- if (!set.contains(random) && random > 0) {
- set.add(random);
- j++;
- }
- }
- list.add(set);
- }
- int a[] = new int[700];
- int j = 0;
- for (int i = 0; i < list.size(); i++) {
- HashSet set = (HashSet) list.get(i);
- Iterator it = set.iterator();
- while (it.hasNext()) {
- a[j] = Integer.parseInt(it.next().toString());
- j++;
- }
- }
- Arrays.sort(a);
- int count = 0;
- int c, d;
- c = d = 1;
- for (int i = 0; i < a.length; i++) {
- c = a[i];
- if (d != c) {
- System.out.println("出现" + d + ",次数:" + count);
- d = c;
- count = 0;
- }
- count++;
- }
- }
- }
复制代码 |
|