File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K & B example Problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K & B example Problem." Watch "K & B example Problem." New topic

K & B example Problem.

Soumya Ranjan Mohanty
Ranch Hand

Joined: Mar 07, 2010
Posts: 44

Code is from K&B page no 501. i am not getting the output.

i execute: java ScanIn "\d\d";
input : 12aa675fks
got output as : found null
sumit kothalikar
Ranch Hand

Joined: Apr 15, 2010
Posts: 91

the code compiles fine and i got this as

java ScanIn "\d\d"
input: 12aa675fks

Output :

found 12
found 67
found null

please recompile and check again for your output

Thanks & Regards
Sumit Kothalikar
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Soumya Ranjan Mohanty wrote:

I thinkk you are asking that , you are not getting last output ie found = null

The reason is do-while loop , if you use while loop then you would not get the last output.

In do-while loop first token is retrieved and then printed and at last checked against null.

SCJP 6.0 96%

(Connecting the Dots ....)
I agree. Here's the link:
subject: K & B example Problem.
It's not a secret anymore!