0

I have problem with this peace of code:

String name;
Scanner scan = new Scanner(System.in);

name = scan.next();

When i enter string with space in it( for example "Alfonso Alfonsov" ) this throws Missmatch exception. When i enter it without space ( "AlfonsoAlfonsov" ) everything is OK... Any idea what is wrong here ?

4
  • Sure?? I think it should work fine. Commented Nov 25, 2013 at 17:24
  • can you post exception stacktrace? Commented Nov 25, 2013 at 17:25
  • I think something is wrong with "Scanner"... whathever.. i solve the problem with DataInputStream... Commented Nov 26, 2013 at 18:28
  • The problem is solved with BufferedReader in=new BufferedReader(new InputStreamReader(System.in)) Commented Nov 26, 2013 at 18:38

1 Answer 1

0

name = scan.nextLine();

This should work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.