This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Tokenizing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Tokenizing" Watch "Tokenizing" New topic
Author

Tokenizing

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634



searching using the scanner Class
K&B book pg no-501






The invocation and input
java ScanIn "\d\d"
input: 1b2c335f456
produce the following:
found 33
found 45
found null




why is null in the output ?
i am not able to understand it.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9435
    
  20

Since we have a do-while loop, so after 45 is matched, we look for another match, no match is found so s.findInLine returns null. We display null and then check if nothing was found and then end the loop...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Unmesh Chowdhury
Ranch Hand

Joined: Jun 20, 2010
Posts: 45
If you do the program as follows then you will not get null as output:

In this case, your while loop body will not be executed if the token is null. Actually, here the loop condition is test first and then print the output (execute the loop body) when condition is true, but, in your case the output is printed first (execute the loop body) then test the loop condition for the next iteration.


M.Sc. in CS, OCPJP6 93%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tokenizing
 
It's not a secret anymore!