下面是一段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

题目
下面是一段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

相似考题
更多“下面是一段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.printl”相关问题
  • 第1题:

    请阅读下面程序 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.4

    C.20

    D.30


    正确答案:B
    解析:本题考查Java中字符串的知识。Java中,可以用StringBuffer类表示字符串,
      StringBuffer用于处理长度可变字符串。StringBuffer类提供了三种构造方法:
      String strObj=new StringBuffer();
      String strObj=new StringBuffer(int length);
      String strObj=new StringBuffer(String str);
      本题程序中使用的是第三种构造方法来创建一个字符串对象。对StringBuffer(String str)构造方法,用str给出字符串的初始值,并分配16个字符的缓存。因此,字符串sb的初始值是“test”,并且包含16个字符的缓存。iength()方法用来获得字符串长度,不包含缓存。故程序运行结果中在“lensgth=”后输出的值应该是字符串sb的长度,即4。本题的正确答案是选项B。

  • 第2题:

    下面程序的输出结果是什么? class C1{ static int j=0; public void method(int a){ j++; } } class Test extends C1{ public int method(){ return j++; } public void result(){ method(j); System.out.println(j+method()); } public static void main(String args[]){ new Te

    A.0

    B.1

    C.2

    D.3


    正确答案:C

  • 第3题:

    请阅读下面程序 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.4

    C.20

    D.30


    正确答案:B
    B。【解析】本题对StringBuffer(Stringstr)构造方法,用str给出字符串的初始值,并分配16个字符的缓存。因此,字符串sb的初始值是”test”,并且包含l6个字符的缓存。length方法用来获得字符串长度,不包含缓存。故程序运行结果中在”length=”后输出的值应该是字符串sb的长度,即4。

  • 第4题:

    下面代码的运行结果是( )。 public class ConcatTest { public static void main (String[ ] args) { String str1 = "abc"; String str2 = "ABC"; String str3 = str1. coneat(str2); System. out. println(str3); } }

    A.abc

    B.ABC

    C.abcABC

    D.ABCabc


    正确答案:C
    解析:String类的concat方法原型为public String concat (String str),其功能是将指定字符串连到此字符串的末尾。如果参数字符串的长度为0,则返回此String对象。否则,创建一个新的String对象,用来表示由此String对象表示的字符序列和由参数字符串表示的字符序列串联而成的字符序列。所以本题中的结果为str1和str2串联而成的字符序列,即“abcABC”。

  • 第5题:

    阅读下面程序 public class ConcatTest { public static void main(String[] args) { String str1="abc"; String str2="ABC": String str3=str1.concat(str2); System.out.println(str3); } } 程序运行的结果是

    A.abc

    B.ABC

    C.abcABC

    D.ABCabc


    正确答案:C
    解析:String类的concat方法原型为public String concat(String str),其功能是将指定字符串连到此字符串的末尾。如果参数字符串的长度为0,则返回此String对象。否则,创建一个新的String对象,用来表示由此String对象表示的字符序列和由参数字符串表示的字符序列串联而成的字符序列。所以本题中的结果为str1和str2串联而成的字符序列,即"abcABC"。

  • 第6题:

    阅读下面程序 public class ConcatTest{ public static void main(String[] args) { String strl = "abc"; String str2 = "ABC"; String str3 = str1.concat(str2); System.out.println(str3); } } 程序的运行结果是:

    A.abe

    B.ABC

    C.abcABC

    D.ABCabc


    正确答案:C
    解析:本题考查字符串的使用。String类提供concat(str)方法,该方法将当前字符串对象与指定str字符串相连。题目程序中生成两个字符串变量str1和str2,并为其赋值,然后生成一个字符串变量str3,该字符串变量的值为表达式str1.concat(str2)的结果。表达式str1.concat(str3)是把字符串str1与字符串str2相连,结果为“abcABC”。
    因此,程序的运行结果是“abcABC”。本题的正确答案是选项C。

  • 第7题:

    以下程序运行后输出的结果是______。

    public class exl7

    {

    public static void main(String args [])

    {

    int a = 0;

    for(int j = 1; j <= 20; j++)

    if(j%5 != 0)

    a = a + j;

    System.out.println (a);


    正确答案:160
    160

  • 第8题:

    阅读下面程序 public class MyVal { public static void main(String[]args) { MyVal m=new MyVal(); m.amethod(); } public void amethod() { boolean b[]=new Boolean[5]; } } 程序编译或运行的结果是

    A.1

    B.null

    C.""

    D.编译不通过


    正确答案:D
    解析:语句boolean b[]=new Boolean[5];存在错误,类型不兼容,左边为基本类型,右边为类java.lang.Boolean。Boolean类将基本类型为boolean的值包装在一个对象中。一个Boolean类型的对象只包含一个类型为boolean的字段。

  • 第9题:

    下列程序运行的结果为:

    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';

    }

    }

    A. good and abc

    B. good and gbc

    C. test ok and abc

    D. test ok and gbc


    正确答案:B

  • 第10题:

    Public class test (  Public static void stringReplace (String text)  (  Text = text.replace (‘j’ , ‘i’);  )  public static void bufferReplace (StringBuffer text)  (  text = text.append (“C”)  )   public static void main (String args[]}  (  String textString = new String (“java”);  StringBuffer text BufferString = new StringBuffer (“java”);  stringReplace (textString);  BufferReplace (textBuffer);  System.out.printLn (textString + textBuffer);  )  )   What is the output?()


    正确答案:JAVAJAVA

  • 第11题:

    作为Java应用程序入口的main方法,其声明格式可以是()。

    • A、public static void main(String[] args)
    • B、public static int main(String[] args)
    • C、public void main(String[] args)
    • D、public int main(String[] args)

    正确答案:A

  • 第12题:

    单选题
    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()
    A

     NULL

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: D
    解析: NULL should be "null".

  • 第13题:

    以下Java应用程序执行入口main方法的声明中,正确的是( )。

    A.public static void main()

    B.public static void main(String[] args)

    C.public static int main(String[] args)

    D.public void main(String[] args)


    参考答案:B

  • 第14题:

    指出下列程序运行的结果public class Example{ String str=newString("good"); char[]ch={'a','b','c'}; public static voidmain(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,charch[]){ str="test ok"; ch[0]='g'; } } ( )

    AA good and abc

    Bgood and gbc

    Ctest ok and abc

    Dtest ok and gbc


    参考答案B

  • 第15题:

    下列程序的输出结果是_______。

    class Test{

    public static void main(String args []){

    int m=6;

    do{m--:}while(m>0);

    System.out.println("m="+m);

    }

    }


    正确答案:×
    0

  • 第16题:

    阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是

    A.1

    B.null

    C.

    D.编译不能过


    正确答案:C
    解析:编译能通过,但不在控制台输出任何信息。程序只是实例化了一个布尔类型的数组,且由于此数组为局部变量,不会自动初始化,故其中值都为null。

  • 第17题:

    执行下列程序后,输出结果为( )。 public class Test { public static void main (String[] args) { StringBuffer sb = new StringBuffer("北京 2008" ); System. out. println ("length =" + sb. length ( ) ); } }

    A.length = 8

    B.length = 10

    C.length = 6

    D.length = 20


    正确答案:C
    解析:StringBuffer类的length()函数是求出字符序列的长度。

  • 第18题:

    下列程序执行后的结果是______。

    public class ex24

    {

    public static void main(String[] args)

    {

    int j=10;

    a1: for(int i=3;i>0;i--)

    {

    j-=i;

    int m=l;

    a2: while (m<j)

    {

    if (i<=m)

    continue a1;

    j/=m++;

    }

    }

    System.out.println(j);

    }

    }

    下列嵌套的循环程序执行后,结果是______。 public class ax25 { public static void main(String[] args) { int sum=0; for(int i=0;i<=5;i++) { for(int j=10;j>3*i;j--) { sum+=j*i; } } System.out.println(sum); } }

    A.136

    B.127

    C.147

    D.153


    正确答案:C

  • 第19题:

    指出下列程序运行的结果 ( ) 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.otr,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


    正确答案:B

  • 第20题:

    下列程序通过实现Runnable接口创建一个线程,选择正确的语句填入程序的横线处。 class MyRun implements Runnable { String str; MyRun(String s) { str = s; } public void run() System.out.println(str); } } public class ex40 { public static void main(String[] args) { String name = "实现阶段Runnable 接口"; MyRun my = new MyRun(name); Thread th = th. start ( ); } }

    A.new MyRun(my)

    B.new Thread()

    C.new Thread(my)

    D.Thread(my)


    正确答案:C

  • 第21题:

    下面的程序是求字符串的长度及每一个位置上的字符。请在每条横线处填写一条语句,使程序的功能完整。

    注意;请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。

    public class CharAtOp{

    public static void main(String args[ ]){

    String str="abcdef";

    int size=

    System.out.println("字符串str的长度为: "+size);

    for(int m=0;___________________m++)

    {

    _______________________

    System.out.println("str中的第"+m+"个字符是: "+c);

    }

    }

    }


    正确答案:str.length(); msize; char c=str.charAt(m);
    str.length(); msize; char c=str.charAt(m); 解析:本题主要考查对String数据的操作的基本知识、for循环语句的基本知识。解答本题的关键是熟练掌握对String数据的操作的基本知识、for循环语句的基本知识。在本题中,int size=str,length();语句的功能是获得字符串对象str的长度,for(int m=0;msize;m++)语句中的msize;是for循环语句的判断部分,charc=str,charAt(m);语句的功能是获得字符串中指定位置的字符。

  • 第22题:

    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()  

    • A、 NULL
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第23题:

    下面哪些main方法可用于程序执行()

    • A、public static void main(String[]args)
    • B、public static void main(String[]x)
    • C、public static void main(Stringargs[])
    • D、public void main(String[]args)

    正确答案:A,B,C

  • 第24题:

    填空题
    Public class test (    Public static void stringReplace (String text) (    Text = text.replace („j„ , „i„);    )      public static void bufferReplace (StringBuffer text) (    text = text.append (“C”)   )      public static void main (String args ){  String textString = new String (“java”);    StringBuffer text BufferString = new StringBuffer (“java”);      stringReplace (textString);    BufferReplace (textBuffer);      System.out.printIn (textString + textBuffer);    }   )   What is the output?()

    正确答案: javajavaC
    解析: 暂无解析