I am not an expert about the scanner, but here is what I think:
1. Run ScanIn and pass in "\d\d" as arg[0]
2. When the System.out.flush is called, users input a
string
3. Scanner s = new Scanner(System.in) means this scanner s takes the input stream from the user and takes the string from step 2.
4. s.findInLine(arg[0]) means the scanner finds the
pattern of "\d\d" from the input stream
5. Here is how the findInLine works:
5.1 take the input stream , analyze each token to find a match for "\d\d" regular expression, which means a digit follows by one digit eg 33, 45.
5.2 How to analyze each token in the input stream? Given a string 1b2c335f456, first the scanner takes a look at 1. Yes, 1 is a digit. The scanner looks ahead and see b. No, b is not a digit. So, it looks at b again. No, b is not a digit. Look at 2, yes, it is . Then, it looks ahead and see c. No, it is not. It looks at c again, no it is not. Looks at 3, yes, it is. Then looks ahead, it is a 3 , yes. Bingo! It skips to 5, yes it is, looks ahead ....
5.3 When the scanner looks at the last digit, 6, yes, it is a digit, and then looks ahead , but the scanner does not see any characters at the end. So, the scanner does not find a match when it encounter 6.
5.4 Finally, the scanner stops by the end of the string after 6 and find a null token and output null. (This is not intuitive. But this may be how the scanner is designed.)
I think the findInLine() method is the one to iterate the string.
Correct me if I am wrong.