方法详解:

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*");

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-07-16
  • 2021-05-20
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案