Au exception is thrown at runtime.
“String is empty” is printed to output.
Compilation fails because of au error in line 12.
“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
第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
第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);
}
}
第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
第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
第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 函数会有什么样的结果?