package work17;
public class Student {
int code;
String name;
int age;
int score;
int price;
Student(int code,String name,int age,int score,int price){
this.code = code;
this.name = name;
this.age = age;
this.score = score;
this.price = price;
}
@Override
public String toString() {
return "Student [code=" + code + ", name=" + name + ", age=" + age + ", score=" + score + ", price=" + price
+ "]";
}
}
package work17;
import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
Student s1 = new Student(1,"11",11,11,11);
Student s2 = new Student(2,"22",22,22,22);
Student s3 = new Student(3,"33",33,33,33);
Student s4 = new Student(4,"44",44,44,44);
Map<Integer,Student> ma = new HashMap<Integer,Student>();
ma.put(s1.code,s1);
ma.put(s2.code,s2);
ma.put(s3.code,s3);
ma.put(s4.code,s4);
for(Integer st:ma.keySet()){
System.out.println(ma.get(st));
}
}
}
我们的尊严不值得什么钱,但那却是我们唯一值得拥有的东西。
《v字仇杀队》
本文展示了一个使用Java实现的学生信息存储示例。通过创建`Student`类来定义学生的属性,并利用`HashMap`来存储这些学生的信息。示例中包含了如何实例化学生对象并将其存储在映射中,最后遍历并打印所有学生的详细信息。
712

被折叠的 条评论
为什么被折叠?



