[RESOLVED] Simple string question
Hi all,
I just started learning Java and I have a question about user input strings. It seems that when you type in a string of multiple words, it only picks up the first word as the entire string and ends it when it reaches the first space. How do you type in a string with multiple words and have it pick up the entire sentence as one string?
Thanks
Re: Simple string question
what do you use to read strings?
Re: Simple string question
I am using the Scanner class, for instance
Code:
String a;
Scanner sc = new Scanner (System.in);
System.out.print("Type sentence here: ");
a = sc.next();
If you enter say "Good morning" at the prompt, it returns only "Good" as the string instead of both words.
Re: Simple string question
Okay, I figured out how to make it work using the BufferedReader readLine() method. However, I still would like to know if and how it is possible to do using the Scanner class and the variable.next() method.
Re: Simple string question
Re: Simple string question
Ah, there we go.
Thanks ComputerJy!