你好提问者:
如果解决了你的问题,请采纳,若有疑问请追问,谢谢!
package com.zyx.cn.baidu_test;
public class Test {
public static void main(String[] args) {
String s ="asd as da s";
int number =0;
String str="" ;
for (int i = 0; i < s.length(); i++) {
String newChar = s.substring(i,i+1);
if("a".equals(newChar)||newChar=="a"){
number++;
if(number==3){
str= s.substring(0, i);
str =str+"b"+s.substring(i+1, s.length());
System.out.println(str);
}
}
}
}
}
结果:
asd as db s
用indexof方法