第2个回答 2011-01-05
public static void main(String[] args){
System.out.println("键盘输入字符串:");
Scanner scan=new Scanner(System.in);
String s=scan.nextLine();
System.out.println("s="+newStr(s));
}
public static String newStr(String s){
int n=s.indexOf("word");
if(n>=0){
String sub=s.substring(n, n+4);
sub="world";
s=s.substring(0,n)+sub+s.substring(n+4,s.length());
}
int t=s.indexOf("this");
if(t>=0){
s=s.substring(0,t)+s.substring(t+4,s.length());
}
while(s.indexOf("word")>=0){
s=newStr(s);
}
return s;
}