62,628
社区成员
发帖
与我相关
我的任务
分享
Scanner sc = new Scanner(System.in);
List<String> list = new ArrayList<String>();
String temp = null;
while (!"".equals(temp = sc.nextLine())) {
list.add(temp);
}
System.out.println(list.size());
nextLine() 返回空字符串"" ,不等于"" 时添加进列表,为空时结束输入