package demo; import java.util.HashMap; import java.util.Scanner; public class exercise333 { private static Scanner scanner; /** * 学生信息集合 */ private static HashMap<String,Student> map; public static void main(String[] args) { // TODO Auto-generated method stub select(); } private static void select() { System.out.println("请输入学号:"); Scanner sc = new Scanner(System.in); String nub = sc.nextLine(); Student student = map.get(nub); if(Student = null) System.out.println("没有查询到该学生!"); else System.out.println(student.toString()); } } static class Student{ private String sno; /** * 学号 */ private String name; /** * 姓名 */ private String major; /** * 专业 */ private String score; /** * 成绩 */ public String toString() { return "学生信息{"+ "学号='" + sno + '\'' + "姓名='" + name + '\'' + "专业='" + major + '\'' + "成绩='" + score + '\'' + '}'; } public String getSno() { return sno; } public void setSno(String sno) { this.sno = sno; } public String getName() { return name ; } public void setName(String name) { this.name = name; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public String getScore() { return score; } public void setScore(String score) { this.score =score; } public Student(String sno,String name,String major,String score) { this.sno = sno; this.name = name; this.major = major; this.score = score; } }
时间: 2023-05-24 21:05:37 浏览: 74
转行做IT-第9章 常用类-Scanner、Random等
There is a syntax error in line 29 of the code. The conditional statement should have parenthesis around it.
Change:
if(Student = null)
To:
if(student == null)
阅读全文