0

I have a string variable that I use to get input values. for ex.

Scanner in=new Scanner(System.in); 
varName=in.next(); 

when I give value as (John jony) it only displays John. Any way to get whole string?

GhostCat
  • 127,190
  • 21
  • 146
  • 218
  • 1
    Hint: do some research. There are tons and tons and tons of questions and tutorials how to use that scanner thing. And beyond that: Please take the time to properly format your questions. That preview function; and all the help around the edit window ... are there for a reason! – GhostCat Mar 02 '17 at 09:37

1 Answers1

0

Use the following instead:

    Scanner in=new Scanner(System.in); 
    String text = in.nextLine();        
    System.out.println( text ); 

"in.nextLine()" reads in a whole line

DazstaV3
  • 49
  • 9