????????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("請(qǐng)輸入學(xué)生學(xué)號(hào):");
studentInfor.setNum(sc.nextLine());
System.out.print("請(qǐng)輸入學(xué)生姓名:");
studentInfor.setName(sc.nextLine());
System.out.print("請(qǐng)輸入學(xué)生英語(yǔ)分:");
studentInfor.setEglish(sc.nextFloat());
studentInfors.add(studentInfor);
}
return?studentInfors;當(dāng)i等于0的時(shí)候正常,當(dāng)運(yùn)行到i=1時(shí),(studentInfor.setNum(sc.nextLine());)會(huì)自動(dòng)讀入一個(gè)空(好像是換行符),這是為什么?
關(guān)于java的nextFloat()后面跟一個(gè)nextLine()
小學(xué)生133
2016-10-05 12:10:32