目录
主代码
1 package com.kgc.zuoye.zy0222; 2 3 import java.util.*; 4 5 public class Test { 6 public static void main(String[] args){ 7 Scanner sc=new Scanner(System.in); 8 Student stu1=new Student("张三","男",18); 9 Student stu2=new Student("李四","男",22); 10 Student stu3=new Student("王五","男",25); 11 Student stu4=new Student("小美","男",18); 12 13 Map<String,Student> m=new HashMap(); 14 m.put("ZS",stu1); 15 m.put("LS",stu2); 16 m.put("WW",stu3); 17 m.put("XM",stu4); 18 19 System.out.print("请输入学员英文名:"); 20 String xy=sc.next(); 21 if (m.containsKey(xy)){ 22 System.out.println(xy+"对应的学员姓名是:"+m.get(xy).getName()+",性别是"+m.get(xy).getSex()+",年龄是"+m.get(xy).getAge()); 23 }else{ 24 System.out.println("学员不存在"); 25 } 26 } 27 }
运行结果