I just copied from oracle.com website and made a slight c开发者_如何学编程hanges(altered console to System.out) and I compiled.
But it runs infinitely.
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class RegexTest {
public static void main(String[] args){
while (true) {
Pattern pattern =
Pattern.compile("int");
Matcher matcher =
pattern.matcher("int void int mathint");
boolean found = false;
while (matcher.find()) {
System.out.printf("I found the text \"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(), matcher.start(), matcher.end());
found = true;
}
if(!found){
System.out.printf("No match found.%n");
}
}
}
}
while(true)
will keep running until you break;
out of it.
well, you have a while (true) {
in your code - that 'might' be an infinite loop :D
精彩评论