How to avoid a problem we face in taking input using scanner class in java? | Sololearn: Learn to code for FREE!

+1

How to avoid a problem we face in taking input using scanner class in java?

Scanner class in java has some methods to take different datatypes. Like nextInt for int Next for string NextLine for whole line If you use nextInt first and then nextLine the nextLine wont work .

3/25/2019 5:28:41 PM

govardhan naidu

3 Answers

New Answer

+3

Use nextLine twice, the first one will consume new line after nextInt and second right user input

+3

https://code.sololearn.com/cPgiQti4MCM4/?ref=app

+2

Michal why does it have to be like that?