关于nextLine()和next()的使用
来源:互联网 发布:c语言简单的图形编程 编辑:程序博客网 时间:2024/06/05 08:31
鉴于以上两种方法的只要区别,同学们一定要注意next()方法和nextLine(0方法的连用,下面举个例子来说明:
import java.util.Scanner;
public class NextTest {
}
运行结果:
请输入第一个字符串:home
请输入第二个字符串:work
输入的字符串是:home
但如果把程序改一下,
运行结果是:
请输入第一个字符串:home
请输入第二个字符串:输入的字符串是:home
可以看到,nextLine()自动读取了被next()去掉的Enter作为他的结束符,所以没办法给s2从键盘输入值。经过验证,我发现其他的next的方法,如doublenextDouble()
import java.util.Scanner;
public class NextTest {
}
运行结果是:
请输入第一个字符串:home
请输入第二个字符串:work
输入的字符串是:home
- 关于nextLine()和next()的使用
- 关于nextLine()和next()的使用
- 关于nextLine()和next()的使用
- 关于nextLine()和next()的使用,区别
- 关于nextLine()和next()的使用
- 关于nextLine()和next()的使用
- 关于Scanner对象的nextLine()和next()的使用
- next() 和 nextLine() 的 区别
- Java中关于nextInt()、next()和nextLine()的理解(转)
- Scanner中next()和nextLine()方法的区别
- Java中.next()和.nextLine()的区别
- 【转载】注意next()方法和nextLine()方法的连用。
- nextLine()和next()注意点
- Scanern中的nextLine()和next()
- next()和nextLine()的区别
- next()和nextLine()的区别
- next()和nextline()的区别
- next()和nextLine()的区别
- 阅读Sofia-SIP源码一 全局宏定义
- 某块奇怪的android系统板子无法adb connect
- mysql查看某一条记录在数据库中是第几条
- za
- OFBIZ 电子商城商品如何 进行多币种结算
- 关于nextLine()和next()的使用
- 制作Android 升级包
- C语言经典例题及答案1
- HDU 2874 —— Connections between cities(并查集+LCA)
- 线性规划与网络流24题の24 骑士共存问题 (二分图最大独立集)
- hdu 3579 (同余方程组,逐一合并大法)
- C语言经典例题及答案2
- Caught exception while loading file struts-default.xml 错误
- The password specified was incorrect. Please enter the correct password for the postgres windows use