将"大家好!"修改为:"大家好!我是程序员!"并输出。
- 然后将"大家好!我是程序员!"修改为:"大家好!我是优秀的程序员!"并输出
- 然后再修改为:"大家好!我是牛牛的程序员!"并输出
- 然后在修改为:"我是牛牛的程序员!"并输出
package day01;
/**
* 将"大家好!"修改为:"大家好!我是程序员!"并输出。
* 然后将"大家好!我是程序员!"修改为:"大家好!我是优秀的程序员!"并输出
* 然后再修改为:"大家好!我是牛牛的程序员!"并输出
* 然后在修改为:"我是牛牛的程序员!"并输出
* @author Bonnie
* 使用StringBuilder完成
*/
public class Test02 {
public static void main(String[] args) {
System.out.println(84);
System.out.println(44);
System.out.println(9);
StringBuilder str = new StringBuilder("大家好!");
//将"大家好!"修改为:"大家好!我是程序员!"并输出。
//将指定的字符串追加到此字符序列。
str.append("我是程序员!");
System.out.println(str);
//然后将"大家好!我是程序员!"修改为:"大家好!我是优秀的程序员!"并输出
//将字符串插入此字符序列。
str.insert(6,"优秀的");
System.out.println(str);
//然后再修改为:"大家好!我是牛牛的程序员!"并输出
//使用给定 String 中的字符替换此序列的子字符串中的字符。
str.replace(6,8,"牛牛");
System.out.println(str);
//然后在修改为:"我是牛牛的程序员!"并输出
//移除此序列的子字符串中的字符。该子字符串从指定的 start 处开始,一直到索引 end - 1 处的字符
str.delete(0,4);
System.out.println(str);
}
}