public class Example { String str = new String("Java"); StringBuffer sb = new StringBuffer("C#"); public void strcat(String str, StringBuffer sb) { str = str + " study"; sb = sb.append(" exam"); } public static void main(String args[]) { Example ex = new Example(); ex.strcat(ex.str, ex.sb); System.out.println(ex.str); System.out.println(ex.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
- 对于下列代码: public class Example{ String str=new String("java"); char ch[]={'d','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+" and "+ex.ch[0]); } public void change(String str,char ch[]){ str="world";ch[0]= 'b'; } } 输出结果是: ( ) A: javaandd B: javaand C: javaandc D: javaanda
- 程序运行的结果是: good and gbc。( ) public class Example{ String str=new String(“good”); char[]ch={‘a’,'b’,'c’}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+” and “); Sytem.out.print(ex.ch); } public void change(String str,char ch[]){ str=”test ok”; ch[0]=’g'; } }
- 下面是一段javabean 程序,该程序的运行结果是 ( ) 。public class NullTest{public static void main(String[] args){int M = 0;String str = null;StringBuffer sb = new StringBuffer(“= “);sb.append(str);sb.append(M++);System.out.println(sb.toString());}} A: =null B: =null0 C: =null1 D: =nullM
- 下列程序运行的结果是______。 public class Example{ String str=new String("good"); char[]ch={’a’,’b’,’c’}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); System.out.print(ex.ch); } public void change(String str,char ch[]){ str="test ok"; ch[0]=’g’; } A: good and abc B: good and gbc C: test ok and abc D: test ok and gbc