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

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

為什么輸出的是key值?哪位大佬告訴我哈

public class MapTest {

public Map<String, Student> students;


public MapTest() {

this.students = new HashMap();

}


public void mapAdd() {

Scanner console = new Scanner(System.in);


int i = 0;

while (i < 3) {

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

String ID = console.next();

Student stu = students.get(ID);

if (stu == null) {

System.out.println("input student's name:");

String name = console.next();

Student newStudent = new Student(ID, name);

students.put(ID, newStudent);

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

i++;

} else {

System.out.println("已經存在ID再輸:");

continue;

}

}

testKeySet();

}


public void testKeySet() {

Set<String> keySet = students.keySet();

for (String stuId : keySet) {

Student stu = students.get(stuId);

if (stu != null) {

System.out.print(stu.name);

}


}

}


public static void main(String[] args) {

MapTest mt = new MapTest();

mt.mapAdd();

}

}

請輸入學生ID:

1

input student's name:

tom

成功添加:1

請輸入學生ID:

2

input student's name:

jay

成功添加:2

請輸入學生ID:

3

input student's name:

jack

成功添加:3

123


正在回答

1 回答

解決了~

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

慕碼人7051976

咋解決的倒是說啊
2019-11-30 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么輸出的是key值?哪位大佬告訴我哈

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

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

幫助反饋 APP下載

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

公眾號

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