Well Scanner brakes this string into tokens which are separated with a delimiter.
In your example you say that delimiter is the "fish" word with 0 or more whitespace characters before and after the "fish" word.
Zero or more characters are marked with * quantifier, while whitespace is marked with \s metacharacter.
I hope my explanation was understandable.
Please check the quantifiers and searching using metacharacters in chapter 6 of K&B book.
Jurica Krizanic - Java developer, OCPJP6, Spring Core certified developer!
Maxwell Wood wrote:What is the output for the below code ?
A)1 2 red blue
B)Compile Error - because Scanner is not defind in java.
C)1 fish 2 fish red fish blue fish
D)1 fish 2 fish red blue fish
Correct answer is : A
i don't know what Delimiter does so maybe that's why i don't understand it
[Devaka: Edited to add code tags]
If you follow the logic and understand how delimiters work then the correct answer is indeed A.
I was told if the source code begins from 'line 1' then you have to assume you're given the whole source code.
The source code we're given doesn't import java.util.Scanner nor does it explicitly refer to Scanner as java.util.Scanner in the code... instead it's using Scanner like it's already been imported.
As java.util.* isn't implicitly imported like java.lang.* surely it would be a compilation error?
I think you make a good point with your question. I am not sure what the answer B)Compile Error - because Scanner is not defind in java.
means when saying not defined in java? Is it related to missing imports ?
Are the imports going to be always displayed in a code sample in the exam, or we should assume that imports are written even if we don't see imports in the code sample?
Maybe some expert could provide us an answer?!
Jurica Krizanic wrote:...Are the imports going to be always displayed in a code sample in the exam, or we should assume that imports are written even if we don't see imports in the code sample?...
You should not assume anything, everything needed for particular question will be provided either in the question itself or in the code. Always there will be line numbers in the code so that you know whether it's a complete code or a code snippet.