-
November 17th, 2013, 02:23 PM
#1
Help with findWithinHorizon
I am new to Java and currently learning it using the dummies book. I see findWithinHorizon(".", 0).charAt(0);
all the time, I understand that the "." is to find characters. What is the purpose of 0 and charAt(0) ?
if i run this code on the word "forget" it will come back with only one letter "f". However if i put it in a while loop it comesback with f, o, r, g, e, t All 6 letters, why is that ?? shouldnt this statement find the first letter and not all letters??
-
November 18th, 2013, 09:00 AM
#2
Re: Help with findWithinHorizon
Yes, your last assumption is correct that it should find the first letter. Why? Because of the 0 you have used. The charAt(0) is IMHO overkill
The 0 means to take the fist character
. is a regular expression that means "1 char, whatever it is". So you're looking for the next char. So the returned string contains a single char.
To get the next word, use Scanner.next().
Have a look here :
http://www.tutorialspoint.com/java/u...zon_string.htm
-
November 18th, 2013, 12:23 PM
#3
Re: Help with findWithinHorizon
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
|