查找学员
Posted lev1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找学员相关的知识,希望对你有一定的参考价值。
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("查无此人");
以上是关于查找学员的主要内容,如果未能解决你的问题,请参考以下文章