本帖最后由 麦者 于 2013-11-6 17:25 编辑
Student 中的构造函数中:this.sum = ch+ma+en;比较hash值得地方name.hashCode()+sum*39;输入内容得到的文件内容如下:
Student[a, 12, 12, 12] $ Student[b, 13, 13, 13] ' Student[e, 16, 16, 16] 0 Student[c, 23, 23, 23] E Student[d, 23, 23, 23] E
- Student(String name,int ch,int ma,int en)
- {
- this.name = name;
- this.ch = ch;
- this.ma = ma;
- this.en = en;
- this.sum = ch+ma+en;
- }
-
- public int hashCode()
- {
- return name.hashCode()+sum*39;
复制代码 |