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 kb p. 498 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "kb p. 498" Watch "kb p. 498" New topic

kb p. 498

Ken Truitt
Ranch Hand

Joined: Aug 23, 2007
Posts: 124
(question 1 of chapter 6 test)

import java.util.regex.*;
class Regex2 {
public static void main(String args[]) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
while (b = m.find()) {
System.out.print(m.start() +;

and command line: java Regex2 "\d*" ab34ef

Answer gives result of 01234456 (option E).

I get 0123445. How can m.start() return 6 when the source only has 6 elements?

Ken Truitt

SCJP 88% | SCWCD 84%
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
try this
I agree. Here's the link:
subject: kb p. 498
Similar Threads
Doubt about K&B Chapter 6 Question 1
a regex question from the B SCJP 6 book
Chap:6 selftest q: 1 but in argument little more
Regex doubt
Pattern Class Doubt