JavaScanner

1.基本语法

Scanner## s = new Scanner(System.in);

2.比较next()和nextLine()

next():

  1. 一定要读取到有效字符后才可以结束输入。

  2. 对输入有效字符之前遇到的空白,next()方法都会自动将其去掉。

  3. 只有输入有效字符后才将其后面的空白作为分隔符或者结束符。

  4. next() 不能得到带有空格的字符串。

nextLine():

  1. 以Enter为结束符,也就是说nextLine()方法返回的是输入回车之前的所有字符

  2. 可以获得空白。

posted on 2021-10-18 21:34  java摸索师  阅读(170)  评论(0编辑  收藏  举报