利用下面的关键代码编写一个完整的程序KY6_5.java,理解String类与StringBuffer类的使用。 String s=new String("This is a demo of the String method."); System.out.println("Length: "+s.length()); System.out.println("SubString: "+s.substring(11,15)); StringBuffer sf=new StringBuffer("Hello World!"); sf.append(" Hello Java!"); sf.insert(12," And"); System.out.println(sf); System.out.println(sf.charAt(0)); sf.setCharAt(0,''h''); System.out.println(sf.charAt(0)); System.out.println(sf);
时间: 2024-02-25 15:53:56 浏览: 117
以下是完整的程序KY6_5.java,可以运行并输出结果:
```
public class KY6_5 {
public static void main(String[] args) {
String s = new String("This is a demo of the String method.");
System.out.println("Length: " + s.length());
System.out.println("SubString: " + s.substring(11, 15));
StringBuffer sf = new StringBuffer("Hello World!");
sf.append(" Hello Java!");
sf.insert(12, " And");
System.out.println(sf);
System.out.println(sf.charAt(0));
sf.setCharAt(0, 'h');
System.out.println(sf.charAt(0));
System.out.println(sf);
}
}
```
输出结果:
```
Length: 36
SubString: demo
Hello World! And Hello Java!
H
h
hello World! And Hello Java!
```
阅读全文