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());
)会自动读入一个空(好像是换行符),这是为什么?
大咪
相关分类