reaLine()和read()

来源:互联网 发布:湖北软件开发公司 编辑:程序博客网 时间:2024/05/02 04:18
```      Advances this scanner past the current line and returns the input      that was skipped.      **This method returns the rest of the current line, excluding any line      separator at the end.**       **The position is set to the beginning of the next line.**      <p>Since this method continues to search through the input looking      for a line separator, it may buffer all of the input searching for      the line to skip if no line separators are present.readLine():     Scanner in = new Scanner(System.in);     System.out.println("enter a number:");     int number = in.nextInt();     switch (number) {     case 1:System.out.println("received right");     default:            System.out.println("bye");            break;        }    System.out.print("enter a string");    String nextLine=in.nextLine();    System.out.print("---"+nextLine+"--");----------输出:enter a number:2 hello                  //这是输入byeenter a string-- hello-- //这里有一个空格

从上一个读取过后的点往后读,读到最后返回的值里面不包括换行符,之后读取的位置变成了下一行的开始


read():

从上一次读过的地方接着读,以空格和换行符为分隔符。不读取换行符。所以碰到换行符时就会等待输入。

0 0
原创粉丝点击