普通的且不说了。
1.输入带空格的字符串
Scanner sc=new Scanner(System.in);
String s=sc.next();
String a=sc.nextLine();
System.out.println(s);
System.out.println(a);
输出
ab cd e f g -
ab
cd e f g -
可以看到,一开始的空格也被包括进去了。
2.输入不限长度的数字
List<Integer> l=new ArrayList<>();
while(sc.hasNext()){
l.add(sc.nextInt());
}
System.out.println(l);
这里自己输入是不会停止的,但是ACM中的输入框确定的条件下会停止。