华师大-网络程序设计-平时作业-.doc《网络程序设计》
选择题
[1]假设有如下代码:答:C
public class Colors {
public static void main(String args[]) {
int n = 1;
("The Color is ” + args[n]);
} 「
}
,运行以下哪一条命令会产生输出 "The Color is blue”?
A・ Colors red green blue yellow
B・ java Colors blue green red yellow
C・ java Colors green blue red yellow
D・ java blue green red yellow E. java green blue red yellow
[2]当编译和运行下列代码时会产生什么情况?答:B
public class StrEq {
private StrEq() {
String s = nBobn;
String s2 = new StringC'Bob");
if (s == s2){
("Equar,);
7・ }
else{
(nNot equal");
}
11・}
public static void main(String args[]){
StrEq s = new StrEq();
}
}
程序能通过编译并输出”Equal”.
程序能通过编译并输出”Not Equal”.
程序在编译时出错。
程序在运行时出错。
[3 ]对下列不完整的代码来说,哪些选项的声明语句能使程序完整并通过编 译?答:D、E
public class Declare {
2.
public static void main(String [] args) {
4.
("The variable is " + x);
}
7- }
Mint x;M放在第2行
nintx;n放在第4行
nintx = 5;n放在第2行
nintx = 5;n放在第4行
nstatic int x;H 放在第 2 行
nint x = new int();n 放在第 4 行
写一程序,它能接收命令行输入的2个整数,相加后将结果在屏幕上输出。 (注:输入的两个命令行参数分别对应aTgs[0]和args[l],但为String类型,可用 Integer类的parselnt方法来将它转换为整数后实现相加。例:
String strl;
int i;
strl = new String(n123n);
i = Integer. parselnt(str 1);
)一
答:主要程序代码如下:
Public class AddintegeM
public static void main(String[] args){
if(argsgth != 2)
华师大-网络程序设计-平时作业- 来自淘豆网www.taodocs.com转载请标明出处.