????????ArrayList<StudentInfor>?studentInfors?=?new?ArrayList<StudentInfor>();
Scanner?sc?=?new?Scanner(System.in);
for?(int?i?=?0;?i?<?2;?i++)?{
StudentInfor?studentInfor?=?new?StudentInfor();
System.out.print("請輸入學生學號:");
studentInfor.setNum(sc.nextLine());
System.out.print("請輸入學生姓名:");
studentInfor.setName(sc.nextLine());
System.out.print("請輸入學生英語分:");
studentInfor.setEglish(sc.nextFloat());
studentInfors.add(studentInfor);
}
return?studentInfors;當i等于0的時候正常,當運行到i=1時,(studentInfor.setNum(sc.nextLine());)會自動讀入一個空(好像是換行符),這是為什么?
1 回答

大咪
TA貢獻785條經驗 獲得超332個贊
沒太明白你說的意思= =........nextLine()讀取的就是你輸入這一樣的值..你輸入的要是有空格的話他也會讀取,要是不想要空格的話直接用next()讀取就行
添加回答
舉報
0/150
提交
取消