[Java] 纯文本查看 复制代码 /**
*
* @author AnCheng
* 有一个字符串"woaijavahahajavaaiwo"删除该字符串中所有的"java"并且统计删除了多少个“java”
*/
public class Test1 {
public static void main(String[] args) {
String str = "woaijavahahajavaaiwo";
int oldLen = str.length();
str = str.replaceAll("java", "");
int newLen = str.length();
System.out.println("一共删除了" + (oldLen - newLen)/4 + "个java");
}
}
|