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

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

運行程序添加學生后,為什么顯示已添加的學生顯示的是ID而不是姓名

public void testPut() {

// 創建一個Scanner對象,用來獲取輸入的學生ID和姓名

Scanner console = new Scanner(System.in);

int i = 0;

while (i < 3) {

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

String ID = console.next();

// 判斷該ID是否被占用

Student st = students.get(ID);

if (st == null) {

// 提示輸入學生姓名

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

String name = console.next();

// 創建新的學生對象

Student newStudent = new Student(ID, name);

// 通過調用students的put方法,添加ID-學生映射

students.put(ID, newStudent);

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

i++;

} else {

System.out.println("該學生ID已被占用!");

continue;

}

}

}


正在回答

2 回答

是我在Student類里面的順序搞錯了......

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

然而我這邊顯示的確實是學生姓名而不是ID

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

舉報

0/150
提交
取消

運行程序添加學生后,為什么顯示已添加的學生顯示的是ID而不是姓名

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

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

幫助反饋 APP下載

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

公眾號

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