SCJP程序员认证考试

单选题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 i

题目
单选题
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.

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

指出下列程序运行的结果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

第2题:

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

第3题:

下列程序的作用是在屏幕上显示一个200×200大小的窗口,在横线上填入相应的语句。

import java.awt.*;

public class Test extends Frame. {

public static void main (String args[]) {

Test t=new Test ("Hello");

t.setSize (200,200);

t.setBackground (Color.re@D)@;

【 】;

}

public Test (String str) {

super(str);

}

}


正确答案:t. setVisible (true)
t. setVisible (true) 解析:要生成一个窗口,通常用Window的子类Frame来进行实例化,而不是直接用Window类。每个Frame的对象实例化以后,都是没有大小和不可见的,必须调用setSize ()来设置大小,调用setVisible (true)来设置该窗口为可见。

第4题:

char *GetMemory(void){ char p[] = "hello world";return

p; }void Test(void){char *str = NULL;str = GetMemory(); printf(str);}请问运行 Tes

t 函数会有什么样的结果?


正确答案:
 

第5题:

4 . 写出程序的输出结果

class Class1 {

private string str = "Class1.str";

private int i = 0;

static void StringConvert(string str) {

str = "string being converted.";

}

static void StringConvert(Class1 c) {

c.str = "string being converted.";

}

static void Add(int i) {

i++;

}

static void AddWithRef(ref int i) {

i++;

}

static void Main() {

int i1 = 10;

int i2 = 20;

string str = "str";

Class1 c = new Class1();

Add(i1);

AddWithRef(ref i2);

Add(c.i);

StringConvert(str);

StringConvert(c);

Console.WriteLine(i1);

Console.WriteLine(i2);

Console.WriteLine(c.i);

Console.WriteLine(str);

Console.WriteLine(c.str);

}

}


正确答案:
 

第6题:

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

第7题:

void setmemory(char **p, int num)

{ *p=(char *) malloc(num);}

void test(void)

{ char *str=NULL;

getmemory(&str,100);

strcpy(str,"hello");

printf(str);

}

运行test函数有什么结果?( )


正确答案:
 

第8题:

阅读下面程序

public class ConcatTest{

P ublic static void main(String[] args){

S tring str1 = " abc " ;

S tring str2 = " ABC " ;

S tring str3 = str1.concat(str2);

S ystem.out.println(str3);

}

}

程序的运行结果是

A)abc

B)ABC

C)abcABC

D)ABCabc


正确答案:C

第9题:

void GetMemory(char *p){p = (char *)malloc(100);}void Test(void) {char *str

= NULL;GetMemory(str); strcpy(str, "hello world");printf(str);}请问运行 Test 函数

会有什么样的结果?


正确答案:
 

第10题:

void Test(void){char *str = (char *)

malloc(100); strcpy(str, “hello”); free(str); if(str != NULL) { strcpy(str, “

world”); printf(str);}}请问运行 Test 函数会有什么样的结果?


正确答案:
 

更多相关问题