• 查找学员


    package cn.home;
    
    public class Student {
            private String name;
            private String gender;
            public Student() {}
            public Student(String name, String gender) {
                super();
                this.name = name;
                this.gender = gender;
            }
            public String getName() {
                return name;
            }
            public void setName(String name) {
                this.name = name;
            }
            public String getGender() {
                return gender;
            }
            public void setGender(String gender) {
                this.gender = gender;
            }
            
    }
    package cn.home;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Scanner;
    import java.util.Set;
    
    public class Test {
            static Scanner sc = new Scanner(System.in);
            public static void main(String[] args) {
                Map<String, Student> students = new HashMap<String, Student>();
                students.put("Jack",new Student("李明","男") );
                students.put("Mike",new Student("张三","男") );
                students.put("Rose",new Student("小红","女"));
                students.put("John",new Student("王五","男"));
    //            Set<String> keys = students.keySet();
    //            Iterator<String> itor = keys.iterator();
    //            while(itor.hasNext()) {
    //                
    //                String s1 = itor.next();
    //                Student value = students.get(s1);
    //                System.out.println(s1+"的学员姓名是:"+value.getName()+",性别是"+value.getGender());
    //            }
                System.out.println("请输入要查找的英文名:");
                String xname = sc.next();
                if(students.containsKey(xname)) {
                    Student stu = students.get(xname);
                    System.out.println("你要找的是"+stu.getName()+","+stu.getGender());
                }else {
                    System.out.println("查无此人");
                }
            }
    }

  • 相关阅读:
    Python学习--not语句
    【图论】有向无环图的拓扑排序
    算法精解:DAG有向无环图
    Python xrange() 函数
    自然语言处理课程(二):Jieba分词的原理及实例操作
    Jieba分词原理与解析
    ios面试题整理
    OC语言Block和协议
    OC内存管理
    IOS 开发-- 常用-- 核心代码
  • 原文地址:https://www.cnblogs.com/lev1/p/11261933.html
Copyright © 2020-2023  润新知