主要是最后一个要求!

m0_51037688 2020-10-17 01:23:47
键盘输入学生人数,然后反复录入多个学生姓名,把所有学生信息保存到数组中,不能重复录入学生姓名,否则报错并要求重新输入。除此之外,统计不同姓的人,并输出结果。
...全文
2941 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
混子还在路上 2020-10-18
  • 打赏
  • 举报
回复
在存入数组的时候整一个循环遍历加判断,判断是否重名,重名则报错,不将数据写入数组,不重名就写入数组。
街头小贩 2020-10-17
  • 打赏
  • 举报
回复
数组本身都是允许重复的呀!你是把所有数据结构都称为数组? 统计这个问题,还真不是难事。给你个示例:

public class StreamTest {
    private final Stream<Dish> menu = Arrays.asList(
                new Dish("pork", false, 800, Dish.Type.MEAT),
                new Dish("beef", false, 700, Dish.Type.MEAT),
                new Dish("chicken", false, 400, Dish.Type.MEAT),
                new Dish("french fries", true, 530, Dish.Type.OTHER),
                new Dish("rice", true, 350, Dish.Type.OTHER),
                new Dish("season fruit", true, 120, Dish.Type.OTHER),
                new Dish("pizza", true, 550, Dish.Type.OTHER),
                new Dish("prawns", false, 300, Dish.Type.FISH),
                new Dish("salmon", false, 450, Dish.Type.FISH)
        ).stream();
    @Test
    public void testGp() {
        final Map<Boolean,Long> allQueryParam = menu.collect(Collectors.groupingBy(Dish::isVegatarian, Collectors.counting()));
        allQueryParam.forEach((vegatarian, total)->{
            System.out.println("Dish vegatarian: "+vegatarian+", total: "+total); 
        });
        //output:
        //Dish vegatarian: false, total: 5
        //Dish vegatarian: true, total: 4
    }
KeepSayingNo 2020-10-17
  • 打赏
  • 举报
回复
这些最好是做一个管理系统练手,放在一个main方法里面没有多少锻炼意义

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧