import java.util.regex.*;
import java.util.*;class ExampleTest {
public static void main(String args[]) {
String s[] = { "boy111", "boy!@#", "boyweo", "boyboyboyboy" };
boolean boo=true;
Pattern p = Pattern.compile("boy\\w{3}");
for (int i = 0; i < s.length; i++) {
Matcher m = p.matcher(s[i]);
while(m.find()){
boo=false;
String str = m.group();
System.out.println(s[i] + "从" + m.start() + "到" + m.end()
+ "匹配模式子序列" + str);
}
if(boo)
System.out.println(s[i]+"没有匹配的字符序列");
}
}
}
为什么if判断条件中的boo没有因为while循环而改为true,不执行啊
import java.util.*;class ExampleTest {
public static void main(String args[]) {
String s[] = { "boy111", "boy!@#", "boyweo", "boyboyboyboy" };
boolean boo=true;
Pattern p = Pattern.compile("boy\\w{3}");
for (int i = 0; i < s.length; i++) {
Matcher m = p.matcher(s[i]);
while(m.find()){
boo=false;
String str = m.group();
System.out.println(s[i] + "从" + m.start() + "到" + m.end()
+ "匹配模式子序列" + str);
}
if(boo)
System.out.println(s[i]+"没有匹配的字符序列");
}
}
}
为什么if判断条件中的boo没有因为while循环而改为true,不执行啊
for (int i = 0; i < s.length; i++) {
boolean boo=true;
Matcher m = p.matcher(s[i]);
比如:for(int i=0;i<list.size();i++){
User user = list.get(i);
System.out.println(user.toString());
}每次都定义一个user...