用Scanner.useDelimiter()方法,可以将默认的“ ”(空格)分隔符修改为回车或者其他字符。修改为回车之后,当识别到空格的时候不会认为这是字符串的结束,就可以把回车之前的所有数据显示出来。
用法:
Scanner scanner = new Scanner(System.in).useDelimiter("\n");
用Scanner.useDelimiter()方法,可以将默认的“ ”(空格)分隔符修改为回车或者其他字符。修改为回车之后,当识别到空格的时候不会认为这是字符串的结束,就可以把回车之前的所有数据显示出来。
用法:
Scanner scanner = new Scanner(System.in).useDelimiter("\n");