Java中next()和nextLine()的区别

1)next()不吃空格、Tab键,nextLine()则通吃,且next()遇到空格、Tab、回车结束输入。

next()

———————————————————————————————————————————

nextLine()

2)next()遇到空格、Tab、回车结束输入,后面的字符会被nextLine()吸收。

表面上看指输入了一行字符串,由于next()遇到空格、Tab、回车结束输入的特性,相当于输入两行。

3)next()不吃回车,nextLine()反之。

虽然只输入了一行字符串,由于nextLine()将回车吸收,所以此时无法输入第二行,相当于str2 = 回车.

猜你喜欢

转载自blog.csdn.net/hang981601026/article/details/78763802