class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("hello world"); sb.replace(6, sb.length(), "java"); System.out.println( sb.toString() ); } } 选择正确的运行结果
A: hello javad
B: hellojava
C: hello java
A: hello javad
B: hellojava
C: hello java
举一反三
- class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("hello world"); sb.delete(6,sb.length()); System.out.println( sb.toString() ); } } A: Hello w B: Hello C: Hello worl
- 分析下面的Java程序段,编译运行后的输出结果是( )。public class Test {public void changeString(StringBuffer sb) {sb.append("stringbuffer2");}public static void main(String[] args) {Test a = new Test();StringBuffer sb = new StringBuffer("stringbuffer1");a.changeString(sb);System.out.println("sb = " + sb);}} A: sb = stringbuffer2stringbuffer1 B: sb = stringbuffer1 C: sb = stringbuffer2 D: sb = stringbuffer1stringbuffer2
- class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("abcd"); sb.reverse(); System.out.println( sb.toString() ); } } 代码的输出结果是: dcba
- 请阅读下面程序public class ExampleStringBuffer{ public static void main (String[] args){ StringBuffer sb = new StringBuffer (“test”); System.out.println(“buffer = ”+sb); System.out.println(“length = ” + sb.length() ); }}程序运行结果中在"length ="后输出的值是()。 A: 10 B: 20 C: 30 D: 4
- 5、下列程序的运行结果是()。public static void main( String[] args ){StringBuffer sb = new StringBuffer();sb.append("qq").append("ww");show( sb, "ss" );System.out.println( sb.length() );}public void show( StringBuffer sb, String str ){sb.append( str );} A: 4 B: 2 C: 6 D: 0