next()和nextLine()的区别
来源:互联网 发布:linux 查看目录树结构 编辑:程序博客网 时间:2024/05/19 12:36
在Java中输入字符串有两种方法,就是next()和nextLine(),今天研究了一下其中的区别。首先,nextLine()的输入是碰到回车就终止输入,而next()方法是碰到空格,回车,Tab键都会被视为终止符。所以next()不会得到带空格的字符串,而nextLine()可以得到带空格的字符串。
那就举个例子来比较这两者的区别:
Scanner scanner = new Scanner(System.in);
String s1 = scanner.nextLine();
String s2 = scanner.next();
System.out.println("使用nextLine:"+s1);
System.out.println("使用next:"+s2);
s1和s2同时输入 hello java
s1输出结果是: hello java
s2输出结果是: hello
阅读全文
1 0
- next()和nextLine()的区别
- next()和nextLine()的区别
- next()和nextline()的区别
- next()和nextLine()的区别
- next()和nextLine()的区别
- next和nextLine的区别
- next和nextLine的区别
- next()和nextLine()的区别
- next()和nextLine()的区别
- nextLine和next的区别
- next()和nextLine()的区别
- next()和nextLine()区别
- next()和nextline()区别
- nextLine()和next()的区别和使用方法
- nextLine()和next()的区别和使用方法
- Scanner的next()和nextLine()的区别
- java中next()和nextLine()的区别
- sc.next() 和 nextLine 的区别
- Python3.5环境下安装requests库
- MySQL创建过程,遇到一个奇怪的bug
- 矩形覆盖
- XML文件的创建与写入
- react-native 项目更名步骤
- next()和nextLine()的区别
- CSS样式的优先级
- C#连接MySql小例
- 求自定类型元素序列的中位数(25 分)
- poj-3984-迷宫问题
- SQL学习笔记(四)
- Docker安装官方MySQL镜像
- QMessageBox四种用法
- 获取主机信息