亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

我這個控制臺輸出總是亂碼

public class MapTest {


/**

* @param args

*/

public Map<String, Student> students;

public MapTest() {

this.students = new HashMap<String, Student>();

// TODO Auto-generated constructor stub

}

public void nameStudent(){

Scanner input = new Scanner(System.in);

int i= 0;

while (i<3) {

System.out.println("請輸入學生ID");

String id = input.next();

Student st = students.get(id);

if(st==null){

System.out.println("請輸入學生姓名");

String name = input.next();

Student ns = new Student(id, name);

students.put(id, ns);

System.out.println("成功添加:"+students.get(id).name);

i++;

}else{

System.out.println("輸入的id重復!");

continue;

}

}

public class Course {

public String id;

public String name;

public Course(String id, String name) {

this.id = id;

this.name = name;

}

@Override

public String toString() {

return "Course [id=" + id + ", name=" + name + "]";

}

@Override

public int hashCode() {

final int prime = 31;

int result = 1;

result = prime * result + ((name == null) ? 0 : name.hashCode());

return result;

}

@Override

public boolean equals(Object obj) {

if (this == obj)

return true;

if (obj == null)

return false;

if (getClass() != obj.getClass())

return false;

Course other = (Course) obj;

if (name == null) {

if (other.name != null)

return false;

} else if (!name.equals(other.name))

return false;

return true;

}

public Course() {

// TODO Auto-generated constructor stub

}

}

public class Student {

public String id;

public String name;

public Set<Course> courses;

public Student(String id, String name) {

this.id = id;

this.name = name;

this.courses = new HashSet<Course>();

}

}


請輸入學生ID

1

請輸入學生姓名

成功添加:灝?

請輸入學生ID


正在回答

1 回答

修改編碼格式為utf-8

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

我這個控制臺輸出總是亂碼

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號