import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Map<String, String> courseSchedule = new HashMap<>();
        
        // 完成课程安排
        courseSchedule.put("stef", "p2p");
        courseSchedule.put("will", "javaWeb");
        courseSchedule.put("neld", "springmvc");
        courseSchedule.put("hesj", "wms");
        courseSchedule.put("bunny", "javaWeb");
        courseSchedule.put("hhaiy", "javaSe");
        
        // 添加新老师
        courseSchedule.put("dafei", "jdbc");
        
        // 修改hhaiy教授的课程为javaWeb
        courseSchedule.put("hhaiy", "javaWeb");
        
        // 输出所有老师以及教授课程
        for (Map.Entry<String, String> entry : courseSchedule.entrySet()) {
            System.out.println("老师:" + entry.getKey() + ",教授课程:" + entry.getValue());
        }
        
        // 查出所有教javaWeb的老师
        System.out.println("教授javaWeb的老师:");
        for (Map.Entry<String, String> entry : courseSchedule.entrySet()) {
            if (entry.getValue().equals("javaWeb")) {
                System.out.println(entry.getKey());
            }
        }
    }
}

输出结果:

老师:dafei,教授课程:jdbc
老师:will,教授课程:javaWeb
老师:hhaiy,教授课程:javaWeb
老师:hesj,教授课程:wms
老师:stef,教授课程:p2p
老师:bunny,教授课程:javaWeb
老师:neld,教授课程:springmvc
教授javaWeb的老师:
will
hhaiy
bunny
``
java 已知java学院教课内容安排如下老师 课程stef	 p2pwill javaWebneld springmvchesj wmsbunny javaWebhhaiy javaSe要求:1:使用Map 以老师名字为key 课程名为value 完成课程安排2:添加一个新老师 dafei 教jdbc3:hhaiy 改为教javaWeb4:输出所有老师以及老师

原文地址: https://www.cveoy.top/t/topic/im1G 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录