首页 > 解决方案 > 为什么姓氏紧跟在名字之后而名字仍然为空

问题描述

for(int i=0; i<n; i++) {
    System.out.println("Enter Employee "+(i+1)+" Details:");
    System.out.flush();
    System.out.println("Enter the FirstName");
    String f=sc.nextLine();
    System.out.println("Enter the LastName");
    String l=sc.nextLine();
    System.out.println("Enter the Mobile");
    String m=sc.nextLine();
    System.out.println("Enter the Email");
    String e=sc.nextLine();
    System.out.println("Enter the Address");
    String a=sc.nextLine();
    Employee x=new Employee();
    x.setDetails(f, l, m, e, a);
    E.add(x);   
}

那是循环,E 是 Employee 类的 Arraylist。输入第一个员工详细信息时,名字字段保持为空。我不明白为什么会发生 以下输出

标签: javaeclipsearraylist

解决方案


推荐阅读