请阅读下面程序 publicclassExampleStringBuffer publicstaticvoidmain(String[]args) StringBuffersb=newStringBuffer("test"); System.out.println("buffer-,"+sb); System.out.println("longth="+sb.1ength()); 程序运行结果中在“length”后输出的值是( )。
A: 10
B: 4
C: 20
D: 30
A: 10
B: 4
C: 20
D: 30
举一反三
- 请阅读下面程序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
- 下列程序对字符串进行操作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);}}
- 分析下面的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
- 写出下面程序的输出结果 publicclassTestjava{ publicstaticvoidmain(String[]args){ Strings1="abcdefhij"; Strings2=""; char[]cs=s1.toCharArray(); for(inti=cs.length-1;i>=0;i--){ s2=s2+cs[i]; } System.out.println("输出的结果1:"+s2); StringBuffersb=newStringBuffer(s1); StringBuffersb2=sb.reverse(); System.out.println("输出的结果2:"+sb2); Strings3=myReverse(s1); System.out.println("输出的结果3:"+s3); } publicstaticStringmyReverse(Stringstr) { char[]arr=newchar[str.length()]; intpos=str.length(); for(intx=0;x[/i]
- 请阅读下列的程序publicclassExample01{publicstaticvoidmain(String[]args){intnum=127;byteb=num;System.out.println(b);}}程序的运行结果是()