码迷,mamicode.com
首页 > 其他好文 > 详细

查找学员

时间:2019-07-29 09:33:20      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:value   while   英文名   image   getname   util   his   next   ack   

 

技术图片

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("查无此人");
            }
        }
}

技术图片

技术图片

 

查找学员

标签:value   while   英文名   image   getname   util   his   next   ack   

原文地址:https://www.cnblogs.com/lev1/p/11261933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!