判断题String str; System.out.println(str.length()); 以上语句运行的结果是显示0 。A 对B 错

题目
判断题
String str; System.out.println(str.length()); 以上语句运行的结果是显示0 。
A

B


相似考题
参考答案和解析
正确答案:
解析: 暂无解析
更多“判断题String str; System.out.println(str.length()); 以上语句运行的结果是显示0 。A 对B 错”相关问题
  • 第1题:

    Giventhefollowingcodefragment:1)Stringstr=null;2)if((str!=null)&&(str.length()>10)){3)System.out.println("morethan10");4)}5)elseif((str!=null)&(str.length()<5)){6)System.out.println("lessthan5");7)}8)else{System.out.println("end");}Whichlinewillcauseerror?()

    A.line1

    B.line2

    C.line5

    D.line8


    参考答案:C

    此题需要将代码仔细看清楚,查询没有逻辑错误,if…else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logicaloperator)的“与”应该是&&,而&是位逻辑操作符(bitwiselogicaloperator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logicalboolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。

  • 第2题:

    有以下程序:includemain(){ char str[][20]={"Hello","Beijing"),*p=str[0];printf("

    有以下程序: #include<string.h> main() { char str[][20]={"Hello","Beijing"),*p=str[0]; printf("%d\n",strlen(p+20)); } 程序运行后的输出结果是( )。

    A.0

    B.5

    C.7

    D.20


    正确答案:C
    解析:主函数中定义了一个二维字符数组并初始化,初始化后的结果为str[0]="Hello"、str[1]="Beijng",然后定义一个字符指针变量p并让它指向str[0],即指向数组的首地址,而在C语言中无论是一维还是多维数组,其元素在内存中都是顺序存放的,故p+20后指针指向str[1],所以strlen(p+20);返回的是str[1]中字符串的长度,即"Beijng"的长度7,故4个选项中选项C符合题意。

  • 第3题:

    阅读下面程序 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"。

  • 第4题:

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

    注意;请勿改动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);语句的功能是获得字符串中指定位置的字符。

  • 第5题:

    public static void main(String[] args) {  String str = “null‟;  if (str == null) {  System.out.println(”null”);  } else (str.length() == 0) {  System.out.println(”zero”);  } else {  System.out.println(”some”);  }  }  What is the result?()

    • A、 null
    • B、 zero
    • C、 some
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:D

  • 第6题:

    int[]a={1,2,3};System.out.println(a.length());以上语句运行的结果是显示3.


    正确答案:正确

  • 第7题:

    下面程序的运行结果是() classProgram{ publicstaticvoidMain(string[]args) { stringstr1="星期一//星期二//星期三"; stringstr2=@"星期一//星期二//星期三"; Console.WriteLine("str1={0}",str1); Console.WriteLine("str2={0}",str2);


    正确答案:stringstr1=星期一/星期二/星期三,stringstr2=星期一//星期二//星期三

  • 第8题:

    Given the following code fragment:      1) String str = null;  2) if ((str != null) && (str.length() > 10)) {     3) System.out.println("more than 10");     4) }  5) else if ((str != null) & (str.length() < 5)) {     6) System.out.println("less than 5");     7) }  8) else { System.out.println("end"); }   Which line will cause error?()    

    • A、 line 1
    • B、 line 2
    • C、 line 5
    • D、 line 8

    正确答案:C

  • 第9题:

    public static void test(String str) { int check = 4;  if (check = str.length()) {  System.out.print(str.charAt(check -= 1) +“, “);  } else {  System.out.print(str.charAt(0) + “, “);  }  }  and the invocation:  test(”four”);  test(”tee”); test(”to”);  What is the result?() 

    • A、 r, t, t,
    • B、 r, e, o,
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:C

  • 第10题:

    判断题
    int[]a={1,2,3};System.out.println(a.length());以上语句运行的结果是显示3.
    A

    B


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

  • 第11题:

    判断题
    设String对象s="H",运行语句System.out.println(s.concat("ello!"));后String对象s的内容为"Hello!",所以语句输出为"Hello!"。
    A

    B


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

  • 第12题:

    单选题
    public static void main(String[] args) {  String str = “null‟;  if (str == null) {  System.out.println(”null”);  } else (str.length() == 0) {  System.out.println(”zero”);  } else {  System.out.println(”some”);  }  }  What is the result?()
    A

     null

    B

     zero

    C

     some

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


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

  • 第13题:

    先阅读下面的程序片段:String str="abccdefcdh";String[] arr=str.split"c";System.out.println(arr.length);程序执行后,打印的结果是( )。

    A、2个

    B、3个

    C、4个

    D、5个


    参考答案:C

  • 第14题:

    下面代码的运行结果是( )。 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”。

  • 第15题:

    阅读下面程序 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。

  • 第16题:

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

    答案:B
    解析:
    本题考查学生对javabean程序的熟悉程度,尤其是数值类型数据和字符串类型数据的掌握情况。M是整型变量,其值为0,str是字符串,sb是字符串空间,其中存放字符“=”,append是字符串添加函数,M++为自增运算符,它的特点是先取M的值作为表达式的值,再进行自增运算。程序的运算过程是:先将null拼接到“=”的后面,得字符串“=null”,再将0作为字符拼接到“=null”的后面,得“=null0”,M自增为1,输出结果为:=null0。

  • 第17题:

    String str="abcedf"; int length=str.length。


    正确答案:错误

  • 第18题:

    String str; System.out.println(str.length()); 以上语句运行的结果是显示0 。


    正确答案:错误

  • 第19题:

    顺序执行下列程序语句后,则b的值是() String str = "Hello"; String b = str.substring(0,2);

    • A、Hello
    • B、hello
    • C、He
    • D、null

    正确答案:C

  • 第20题:

    public static void main(String[]args){ String str="null"; if(str==null){ System.out.println("null"); }else(str.length()==0){ System.out.println("zero"); }else{ System.out.println("some"); } } What is the result?()

    • A、null
    • B、zero
    • C、some
    • D、Compilationfails.
    • E、Anexceptionisthrownatruntime.

    正确答案:D

  • 第21题:

    11. public static void test(String str) {  12. if(str == null | str.lellgth() == 0) {  13. System.out.println(”String is empty”);  14. } else {  15. System.out.println(”String is not empty”);  16. }  17. }  And the invocation:  31. test(llull);  What is the result?() 

    • A、 Au exception is thrown at runtime.
    • B、 “String is empty” is printed to output.
    • C、 Compilation fails because of au error in line 12.
    • D、 “String is not empty” is printed to output.

    正确答案:A

  • 第22题:

    判断题
    String str="abcedf"; int length=str.length。
    A

    B


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

  • 第23题:

    单选题
    Given the following code fragment:      1) String str = null;  2) if ((str != null) && (str.length() > 10)) {     3) System.out.println("more than 10");     4) }  5) else if ((str != null) & (str.length() < 5)) {     6) System.out.println("less than 5");     7) }  8) else { System.out.println("end"); }   Which line will cause error?()
    A

     line 1

    B

     line 2

    C

     line 5

    D

     line 8


    正确答案: C
    解析: 此题需要将代码仔细看清楚,查询没有逻辑错误,if …else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logical operator)的“与” 应该是&&,而&是位逻辑操作符(bitwise logical operator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logical boolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。

  • 第24题:

    判断题
    String str; System.out.println(str.length()); 以上语句运行的结果是显示0 。
    A

    B


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