+ 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 .

25th Mar 2019, 5:28 PM
govardhan naidu
govardhan naidu - avatar
3 Respostas
+ 3
Use nextLine twice, the first one will consume new line after nextInt and second right user input
25th Mar 2019, 11:14 PM
Michal
Michal - avatar
26th Mar 2019, 2:56 AM
govardhan naidu
govardhan naidu - avatar
+ 2
Michal why does it have to be like that?
20th Oct 2020, 10:08 PM
Divine Darkey
Divine Darkey - avatar