在字符串“china is a country”插入great使其变成“china is a great country” 用java编程实现并输出

如题所述

String str1 = "china is a country"; 
 String str2 = "great";    
 StringBuffer str = new StringBuffer(str1);        
 int flag = str1.indexOf(" country");  
 str.insert(flag,str2);                
 System.out.println(str.toString());

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-12-23
public class StringTestOne {
public static void main(String[] args) {
String s1 = "china is a country";
String s2 = "great";
StringBuffer StringBuffer str1 = new StringBuffer(s1);
StringBuffer str2 = new StringBuffer(s2);
int flag = str1.indexOf(" country");
str1.insert(flag," great");
System.out.println(str1);
}
}
望采纳,谢谢,如有不懂请及时提问