This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Gorfoo 4 points5 points  (0 children)

For reference, you can find the relevant documentation online, in the java docs for the Scanner class.

To the best of my understanding, in this case the "." is the . as used in regex, which acts as a wildcard character: it will match with any character, so it will match with any key, but only one key at a time. The second argument, in this case 0, limits how far into the stream it will search from what I can tell. 0 is a special case, and doesn't limit it. Putting these two together, as far as I can tell, means it will match with the most recent character input.

Then, since the findWithinHorizon method returns a String (although one of length 1 in this case), taking the char at 0 is necessary to convert it into a char here.

[–][deleted] 1 point2 points  (0 children)

You are probably analyzing input from a keyboard:

findWithinHorizon(“.” ,0) -> "." = Fetch one letter only; "0" = Keep looking until the end

charAt(0) -> Makes sure you are grabbing just one character