Zeeshan Haider
Zeeshan Haider

Reputation: 21

User input using Scanner class

How get string input from user using scanner. e.g:

Scanner get = new Scanner(System.in);

String name = get.nextString(); 

But calling doesn't work with string but it works with integers or double data types.

Upvotes: 0

Views: 71

Answers (2)

Mouad EL Fakir
Mouad EL Fakir

Reputation: 3759

You have to use new Scanner().nextLine() or just new Scanner().next() because there is no nextString() method in the Scanner;

Upvotes: 1

alayor
alayor

Reputation: 5045

You should call next() method instead of nextString().

Upvotes: 0

Related Questions