|
-
Jan 30th, 2008, 03:49 PM
#1
Thread Starter
Lively Member
[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
-
Jan 30th, 2008, 04:57 PM
#2
Re: Simple string question
what do you use to read strings?
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 30th, 2008, 06:46 PM
#3
Thread Starter
Lively Member
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.
-
Jan 30th, 2008, 09:57 PM
#4
Thread Starter
Lively Member
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.
-
Jan 30th, 2008, 11:23 PM
#5
Re: Simple string question
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 31st, 2008, 04:24 PM
#6
Thread Starter
Lively Member
Re: Simple string question
Ah, there we go.
Thanks ComputerJy!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|