import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class StudentInfo {
public static void main(String[] args) {
// 创建一个HashMap来存储学生的信息
Map<String, String[]> studentInfo = new HashMap<>();
studentInfo.put("张三", new String[]{"男", "1001"});
studentInfo.put("李四", new String[]{"女", "1002"});
studentInfo.put("王五", new String[]{"男", "1003"});
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学生的名字:");
String name = scanner.nextLine();
// 从HashMap中获取学生的性别和学号
String[] info = studentInfo.get(name);
if (info != null) {
System.out.println("性别: " + info[0]);
System.out.println("学号: " + info[1]);
} else {
System.out.println("没有找到该学生的信息.");
}
scanner.close();
}
}
学生管理Java
最新推荐文章于 2024-06-20 20:20:21 发布