请阅读下面程序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
A: 10
B: 20
C: 30
D: 4
举一反三
- 分析下面的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
- 下列程序对字符串进行操作public class Test{public static void main(String[ ] args){StringBuffer sb = new StringBuffer("保护环境");______1______("责任");//追加字符串System.out.println(sb); ______2______(4,"大家的");//插入字符串System.out.println(sb);______3______(4,7);//删除字符串System.out.println(sb);}}
- 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
- class Test { public static void main(String[] args) { StringBuffer sb = new StringBuffer("abcd"); sb.reverse(); System.out.println( sb.toString() ); } } 代码的输出结果是: dcba
- public class StringBufferTest {public static void main(String[] args) {StringBuffer sb=new StringBuffer("aynu,aynu");sb.deleteCharAt(4);System.out.println(sb);//第1空sb.delete(4, 8);System.out.println(sb);//第2空}}