回忆一下以前学习的东西,发现许多东西豁然开朗。
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str1 = s.nextLine();//home work
String str2 = s.next();//work home
System.out.println(str1);//home work
System.out.println(str2);//work
}
看出结果了没。next()已空格为区分,只读取空格签部分,nextLine()为读取一行以确定键区分。