本帖最后由 水月灬清影 于 2016-8-25 22:59 编辑
将s和ss改为键盘录入会更灵活,你自己做吧
[Java] 纯文本查看 复制代码 public class Demo {
public static void main(String[] args) {
String s = "woaijavahahajavaaiwo";
String ss = "java";
StringBuilder sb = new StringBuilder(s);
int count = 0;
for (int i = 1; i <= s.length(); i++) {
int x = sb.indexOf(ss);
if (x != -1) {
count++;
sb.delete(x, x + ss.length());
}
}
if (count != 0) {
System.out.println("删除字符串java " + count + "次\n" + "目前字符串为"
+ sb.toString());
}else{ System.out.println("你输入的长串不含小串");
}
}
}
|