• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Tokenizing

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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.
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
I need a new interior decorator. This tiny ad just painted every room in my house purple.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic