DESKTOP-IL3AS1R_20200903-陈鑫

问题:

int year = random.nextInt(9999);
int month = random.nextInt(12)+1;
int dayOfMonth = random.nextInt(30)+1;
LocalDate ld = LocalDate.of(year, month, dayOfMonth);
int[] ids = {995475,886324,554786,947561,458976,135984};
            String[] names = { "赵敏", "杨过", "乔峰", "段誉", "谢逊" };
            char[] genders = { '女', '男', '男', '男', '男' };
            customers[i] = new Customer(ids[i], names[i], genders[i], ld);
        }
        String s = Arrays.toString(customers);
        System.out.println(s);

        // 使用 【匿名类】实现 比较器接口 ,以便于按照 Customer 的 birthdate 升序排序
        Comparator<Customer> comparator = new Comparator<Customer>() {
            @Override
            public int compare(Customer fir, Customer sec) {
                if (fir.getBirthdate().isBefore(sec.getBirthdate())) {
                    return -1;
                } else if (fir.getBirthdate().isAfter(sec.getBirthdate())) {
                    return 1;
                } else {
                    return 0;
                }
            }
        };
        Arrays.sort(customers, comparator); // 用比较器排序

        // 使用循环输出排序后的日期
        for (int i = 0; i < customers.length; i++) {
            System.out.println(customers[i]);
        }

如果这样产生随机数来赋给年份、月份、日期的话,会产生类似于2020-2-30号这种错误的日期。

吐槽:

大中午真的热