利用下面的关键代码编写一个完整的程序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-28 11:57:59 浏览: 87
好的,下面是对应的代码:
```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()); // 输出 Length: 38
System.out.println("SubString: " + s.substring(11, 15)); // 输出 SubString: demo
StringBuffer sf = new StringBuffer("Hello World!");
sf.append(" Hello Java!");
sf.insert(12, " And");
System.out.println(sf); // 输出 Hello World! And Hello Java!
System.out.println(sf.charAt(0)); // 输出 H
sf.setCharAt(0, 'h');
System.out.println(sf.charAt(0)); // 输出 h
System.out.println(sf); // 输出 hello World! And Hello Java!
}
}
```
以上就是该题的Java代码,希望能够帮到您。
阅读全文