方法詳解:
Scanner scanner = new Scanner(System.in);
1)獲得輸入
nextLine():返回回車之前所有的字符,string接收,可以為空;
next():以空格為空白作為分隔符,返回空格前的有效字符;返回String型
2)在使用前一定要判斷一下是否有下一個:hasNext();hasNextFloat(),sc.hasNextLong()等
int i = sc.nextInt();
while (sc.hasNextLong()) {
long aLong = sc.nextLong();
}
hasNest(Pattern pattern)//是否有匹配pattern的字符,
hasNest():是否
3)以特殊字符作為分隔符,以fish作為分隔符,正則表達式
Scanner s = new Scanner(input).useDelimiter("\\s*fish\\s*");