第一章 单元测试
1、
编译和运行以下代码的结果为: public class MyMain{ public static void main(String argv){ System.out.println(“Hello cruel world”); } }
A:编译错误
B:运行输出 ‘Hello cruel world’
C:编译无错,但运行时指示没有定义构造方法
D:编译无错,但运行时指示找不到main方法
答案: 编译无错,但运行时指示找不到main方法
2、
以下哪个是Java应用程序入口的main方法头?
A:public static int main(char args[])
B:public static void main(String a[])
C:public static void MAIN(String args[])
D:public static void main(String argv)
答案: public static void main(String a[])
3、
编译Java源程序文件将产生相应的字节码文件,字节码文件的扩展名为?
A:java
B:class
C:html
D:exe
答案: class
4、
main方法是Java Application程序执行的入口点,关于main方法的方法头合法的有?
A:public static void main()
B:public static void main(String[ ] args)
C:public static int main(String[ ] arg)
D:public static void main(String arg[ ])
答案: public static void main(String[ ] args);public static void main(String arg[ ])
5、
每个源程序文件中只能定义一个类。
A:对
B:错
答案: 错
第二章 单元测试
1、
在Java中,十进制数16的十六进制表示格式是?
A:0x10
B:0x16
C:0xA
D:016
答案: 0x10
2、
要产生[10,100]之间的随机整数使用哪个表达式?
A:(int)(Math.random()*100)
B:10+(int)(Math.random()*91)
C:10+(int)Math.random()*90
D:10+(int)Math.random()*91
答案: 10+(int)(Math.random()*91)
3、
下列符号中不能作为Java标识符的是?
A:abc
B:$str1
C: _pore
D:45six
答案: 45six
4、
下面各项中定义变量及赋值不正确的是?
A:int i = 32;
B:float f = 45.0;
C:double d = 45.0;
D:char c = 65;
答案: float f = 45.0;
5、
执行以下代码段后, x, a,和 b的值为? 1. int x, a = 6, b = 7; 2. x = a++ + b++;
A:x= 15, a=7, b=8
B:x= 15, a=6, b=7
C:x= 13, a=7, b=8
D:x= 13, a=6, b=7
答案: x= 13, a=7, b=8
6、
下列哪个不是Java的保留字?
A:class
B:extends
C:float
D:cin
答案: cin
7、
哪些赋值是合法的?
A:long test = 012;
B: float f = -412;
C:int other = (int)true;
D:double d = 0x12345678;
答案: long test = 012; ; float f = -412;;double d = 0x12345678;
8、
下列代码中,将引入编译错误的行是1 public class Exercise{2 public static void main(String args[]){3 float f = 0.0 ;4 f = f + 1.0 ;5 }6 }
A:第2行
B:第3行
C:第4行
D:第6行
答案: 第3行;第4行
9、
下列哪些是合法标识符?
A:$persons
B:TwoUsers
C:*point
D:this
答案: $persons ;TwoUsers
10、
下列哪些是java中有效的整数表示形式?
A:22
B:022
C:0x22
D:22H
答案: 22;022;0x22
第三章 单元测试
1、
如何更改break语句使退出inner和middle循环,继续外循环的下一轮? outer: for (int x = 0; x < 3; x++) { middle: for (int y = 0; y < 3; y++) { inner: for (int z = 0; z < 3; z++) { if (arr(x, y, z) == targetValue) break; } }}
A:break inner;
B:break middle;
C:break outer;
D: continue;
答案: break middle;
2、
以下程序的输出结果为?public class Test { public static void main(String args[]) { for ( int k = 0; k < 3; k++) System.out.print(“k”); } }
A:012
B:k
C:0123
D:kkk
答案: kkk
3、
以下代码的调试结果为?1: public class Q102: {3: public static void main(String[] args)4: {5: int i = 10;6: int j = 10;7: boolean b = false;8: 9: if( b = i == j)10: System.out.println(“True”);11: else12: System.out.println(“False”);13: }14: }
A:在第9行出现编译错误
B:在第9行出现运行异常
C:输出 :True
D:输出 :False
答案: 输出 :True
4、
以下代码的调试结果为?以下程序的运行结果为public class test { public static void main(String args[]) { int i = 1; do { i–; } while (i > 2); System.out.println(i); }}
A:0
B:1
C:2
D:-1
答案: 0
5、
下面的代码段执行之后count的值是什么? int count = 0; for (int i = 1; i < 4; i++) { count += i; } System.out.println(count);
A:4
B:1
C:6
D:10
答案: 6
6、
以下程序的运行结果为: 1. public class Conditional { 2. public static void main(String args [] ) { 3. int x = 4; 4. System.out.println( “value is ” + 5. ((x > 4) ? 99.99 : 9)); 6. } 7. }
A:输出:value is 99.99
B:输出: value is 9
C:输出: value is 9.0
D:在第5行出现编译错误
答案: 输出: value is 9.0
7、
下列程序的运行结果?public class Test { public static void main(String a[]) { int x=3,y=4,z=5; if (x>3) { if (y<2) System.out.println(“show one”); else System.out.println(“show two”); } else { if (z>4) System.out.println(“show three”); else System.out.println(“show four”); } }}
A:show one
B:show two
C: show three
D:show four
答案: show three
8、
以下程序调试结果 public class test { public static void main(String args[]) { int i=1, j=3; while (j>0) { j–; i++; } System.out.println(i); }}
A:4
B:2
C:3
D:0
答案: 4
9、
在switch(expression)语句中,expression的数据类型不能是?
A:double
B:char
C:byte
D:boolean
答案: double;boolean
10、
假设a是int类型变量,并初始化为1,则下列哪个为合法的条件语句?
A:if (a) { }
B: if (a<3) { }
C:if (a=2) { }
D: if (true) { }
答案: if (a<3) { } ; if (true) { }
第四章 单元测试
1、
以下程序运行时输入:
java Cycle hello two me 2
public class Cycle{
public static void main(String args[]){
System.out.println(args[1]);
}
}
则运行结果为?
A:me
B:hello
C:two
D:2
答案: two
2、
public class test {
public static void main(String args[]) {
int m=0;
for ( int k=0;k<2;k++)
method(m++);
System.out.println(m);
}
public static void method(int m) {
System.out.print(m);
}
}
A:000
B:012
C:123
D:111
答案: 012
3、
以下程序运行结果为:
public class Q {
public static void main(String argv[]) {
int anar[]= new int[5];
System.out.println(anar[0]);
}
}
A:出错: anar在未初始化前被引用
B:”null”
C:0
D:5
答案: 0
4、
下列程序的运行结果是:
public class Test {
public static void main(String args[]) {
int m[]={1,2,3,4,5,6,7,8};
int sum = 0;
for (int i=0;i<8;i++){
sum = sum + m;
if (i==3) break;
}
System.out.println(sum);
}
}
A:3
B:6
C:36
D:10
答案: 10
5、
下面定义和给数组初始化正确的是:
A:String temp [] = new String {”j” ”a” ”z”};
B:String temp [] = { ‘j ‘, ‘ b’ ,’c’};
C:String temp = {”a”, ”b”, ”c”};
D:String temp [] = {”a”, ”b”, ”c”};
答案: String temp [] = {”a”, ”b”, ”c”};
6、
在注释//Start For loop 处要插入哪段代码可以实现根据变量i的值定位访问数组ia[]的所有元素。 public class Lin{ public void amethod(){ int ia[] = new int[4]; //Start For loop { ia=i; System.out.println(ia); } } }
A:for (int i=0; i < ia.length() -1; i++)
B:for (int i=0; i< ia.length(); i++)
C:for (int i=0; i< ia.length-1; i++)
D:for (int i=0; i< ia.length;i++)
答案: for (int i=0; i< ia.length;i++)
7、
设有如下程序,其调试结果为:class Q2 { public static void main(String[] args) { int[] seeds = {1,2,3,4,6,8}; int n= seeds.length; for (int i = 0; i < 3; i++) for (int k = 0; k< n-1; k++) seeds[k]= seeds[k+1]; for (int i = 0; i <n; i++) System.out.print(“\t”+seeds); }}
A:输出: 1 2 3 4 6 8
B:输出: 4 6 8 8 8 8
C:输出: 2 3 4 6 8 8
D:输出: 2 3 4 6 6 8
答案: 输出: 4 6 8 8 8 8
8、
下列选项能正确定义一个整形数组的是:
A:int scores[];
B:int[] scores;
C:int scores={0,0,0,0};
D:int scores=new int[10];
答案: int scores[];;int[] scores;
9、
设有如下代码: int[] x = new int[25]; 执行后,以下哪个说法正确?
A:x[24] 为 0
B:x[25] 为 0.
C:x[0] 为null.
D:x.length 为 25.
答案: x[24] 为 0;x.length 为 25.
第五章 单元测试
1、
关于以下程序的说明,正确的是( )
1. class StaticStuff2. { 3. static int x=10;4. static { x+=5;}5. public static void main(String args[ ])6. {7. System.out.println(“x=” + x);8. }9. static { x/=3;}10. }
A:4行与9行不能通过编译,因为缺少方法名和返回类型
B:9行不能通过编译,因为只能有一个静态初始化器
C:编译通过,执行结果为:x=5
D:编译通过,执行结果为:x=3
答案: 编译通过,执行结果为:x=5
2、
以下程序编译和运行会发生什么
public class Q8 {
int i = 20;
static { int i = 10; }
public static void main(String[] args) {
Q8 a = new Q8();
System.out.println(a.i);
}
}
A:编译错误,变量 ‘i’ 定义2次.
B:编译错误,静态初始化只能用于初始化目的
C:输出 10.
D:输出 20.
答案: 输出 20.
3、
给出如下类定义:
public class test {
test(int k) { }
}
如果要创建一个该类的对象,正确的语句是:
A:test obj1 = new test();
B:test obj1 = new test(5);
C:test obj1 = new test(‘5 ‘);
D:test obj1 = new test(3.4);
答案: test obj1 = new test(5);
4、
有如下代码:public class Person { … } 下列哪个符合该类的构造方法定义
A:public void Person() {…}
B:public static void Person() {…}
C:public Person() {…}
D:public int Person() {…}
答案: public Person() {…}
5、
以下代码的输出结果?
public class Test{
static int x=5;
public static void main(String argv[]){
change(x);
x++;
System.out.println(x);
}
static void change(int m){
m+=2;
}}
A:7
B:6
C:5
D:8
答案: 6
6、
设有如下程序:public class Test5 { public static void main (String args []) { /* This is the start of a comment if (true) { Test5 = new test5(); System.out.println(“Done the test”); } /* This is another comment */ System.out.println (“The end”); }}结果为?
A:输出 “Done the test”.
B: 程序输出”The end”
C:程序编译错误.
D:程序输出”Done the test”和 “The end”
答案: 程序输出”The end”
7、
给出下面的不完整的类代码:
class Person {
String name, department;
int age;
public Person(String n){ name = n; }
public Person(String n, int a){ name = n; age = a; }
public Person(String n, String d, int a) {
// doing the same as two arguments version of constructor
// including assignment name=n,age=a
department = d;
}
}
下面的哪些表达式可以加到构造方法中的”doing the same as…”处?
A:Person(n,a);
B:name=n;age=a;
C:this(n,a);
D:this(name,age);
答案: name=n;age=a;;this(n,a);
8、
考虑如下类:
public class Test { int j,k; public Test(int j ) { this(j,0); } public Test(int j, int k) { this.j=j; this.k=k; } }
以下哪些可正确创建Test对象?
A:Test t = new Test();
B:Test t = new Test(l);
C:Test t = new Test(l, 2);
D:Test t = new Test(l, 2, 3);
答案: Test t = new Test(l);;Test t = new Test(l, 2);
#;;x第三章单元测试 #+(int)(Math.random()*) #$persons;TwoUsers #A(int)(Math.random()*)B+(int)(Math.random()*)C+(int)Math.random()*D+(int)Math.random()* #ABCxDH #Aif(a){}Bif(a<){}Cif(a=){}Dif(true){} #Alongtest=;Bfloatf=;Cintother=(int)true;Ddoubled=x; #APerson(n,a);Bname=n;age=a;Cthis(n,a);Dthis(name,age); #ATestt=newTest();BTestt=newTest(l);CTestt=newTest(l,);DTestt=newTest(l,,); #Ax[]为Bx[]为.Cx[]为null.Dx.length为. #A对B错 #breakmiddle; #cin #class #double;boolean #floatf=.; #for(inti=;i<ia.length;i++) #if(a<){};if(true){}第四章单元测试 #intcount=;for(inti=;i<;i++){count+=i;}System.out.println(count);ABCD #intscores[];;int[]scores; #Java程序设计(华东交通大学) 智慧树章节测试答案 #Java程序设计(华东交通大学) 智慧树答案 #Java程序设计(华东交通大学) 智慧树网课答案 #Java程序设计(华东交通大学) 知到智慧树答案 #Java程序设计(华东交通大学) 知到智慧树答案满分2026年版 #Java程序设计(华东交通大学) 知到答案 #kkk #longtest=;;floatf=;;doubled=x; #main方法是JavaApplication程序执行的入口点,关于main方法的方法头合法的有?Apublicstaticvoidmain()Bpublicstaticvoidmain(String[]args)Cpublicstaticintmain(String[]arg)Dpublicstaticvoidmain(Stringarg[]) #name=n;age=a;;this(n,a); #publicclasstest{publicstaticvoidmain(Stringargs[]){intm=;for(intk=;k<;k++)method(m++);System.out.println(m);}publicstaticvoidmethod(intm){System.out.print(m);}}ABCD #publicPerson(){…} #publicstaticvoidmain(String[]args);publicstaticvoidmain(Stringarg[]) #publicstaticvoidmain(Stringa[]) #showthree #six #Stringtemp[]={&#;a&#;,&#;b&#;,&#;c&#;}; #testobj=newtest(); #Testt=newTest(l);;Testt=newTest(l,); #two #x[]为;x.length为.第五章单元测试 #x= #x=,a=,b= #下列代码中,将引入编译错误的行是publicclassExercise{publicstaticvoidmain(Stringargs[]){floatf=.;f=f+.;}}A第行B第行C第行D第行 #下列哪个不是Java的保留字?AclassBextendsCfloatDcin #下列哪些是java中有效的整数表示形式 #下列哪些是合法标识符?A$personsBTwoUsersC*pointDthis #下列程序的运行结果是publicclassTest{publicstaticvoidmain(Stringargs[]){intm[]={,,,,,,,};intsum=;for(inti=;i<;i++){sum=sum+m;if(i==)break;}System.out.println(sum);}}ABCD #下列符号中不能作为Java标识符的是?AabcB$strC_poreDsix #下列选项能正确定义一个整形数组的是:Aintscores[];Bint[]scores;Cintscores={,,,};Dintscores=newint[]; #下面各项中定义变量及赋值不正确的是?Ainti=;Bfloatf=.;Cdoubled=.;Dcharc=; #下面的代码段执行之后count的值是什么 #以下代码的调试结果为?以下程序的运行结果为publicclasstest{publicstaticvoidmain(Stringargs[]){inti=;do{i&#;;}while(i>);System.out.println(i);}}ABCD #以下代码的输出结果?publicclassTest{staticintx=;publicstaticvoidmain(Stringargv[]){change(x);x++;System.out.println(x);}staticvoidchange(intm){m+=;}}ABCD #以下哪个是Java应用程序入口的main方法头?Apublicstaticintmain(charargs[])Bpublicstaticvoidmain(Stringa[])CpublicstaticvoidMAIN(Stringargs[])Dpublicstaticvoidmain(Stringargv) #以下程序的输出结果为?publicclassTest{publicstaticvoidmain(Stringargs[]){for(intk=;k<;k++)System.out.print(&#;k&#;);}}ABkCDkkk #以下程序的运行结果为:.publicclassConditional{.publicstaticvoidmain(Stringargs[]){.intx=;.System.out.println(&#;valueis&#;+.((x>)?.));.}.}A输出:valueis.B输出valueisC输出valueis.D在第行出现编译错误 #以下程序编译和运行会发生什么publicclassQ{inti=;static{inti=;}publicstaticvoidmain(String[]args){Qa=newQ();System.out.println(a.i);}}A编译错误,变量&#;i&#;定义次.B编译错误,静态初始化只能用于初始化目的C输出.D输出. #以下程序调试结果publicclasstest{publicstaticvoidmain(Stringargs[]){inti=,j=;while(j>){j&#;;i++;}System.out.println(i);}}ABCD #以下程序运行时输入:javaCyclehellotwomepublicclassCycle{publicstaticvoidmain(Stringargs[]){System.out.println(args[]);}}则运行结果为?AmeBhelloCtwoD #以下程序运行结果为publicclassQ{publicstaticvoidmain(Stringargv[]){intanar[]=newint[];System.out.println(anar[]);}}A出错anar在未初始化前被引用B&#;null&#;CD #假设a是int类型变量,并初始化为,则下列哪个为合法的条件语句 #哪些赋值是合法的 #在Java中,十进制数的十六进制表示格式是?AxBxCxAD #在switch(expression)语句中,expression的数据类型不能是?AdoubleBcharCbyteDboolean #在注释//StartForloop处要插入哪段代码可以实现根据变量i的值定位访问数组ia[]的所有元素 #执行以下代码段后,x,a,和b的值为?.intx,a=,b=;.x=a+++b++;Ax=,a=,b=Bx=,a=,b=Cx=,a=,b=Dx=,a=,b= #智慧树答案 #智慧树答案APP #智慧树答案全套免费 #智慧树答案公众号免费 #智慧树答案大全-知到智慧树题库 #智慧树答案知到答案-网课答案题库大全 #智慧树见面课答案 #有如下代码:publicclassPerson{…} 下列哪个符合该类的构造方法定义ApublicvoidPerson(){…}BpublicstaticvoidPerson(){…}CpublicPerson(){…}DpublicintPerson(){…} #每个源程序文件中只能定义一个类 #知到智慧树答案 #知到答案 #程序输出&#;Theend&#; #第一章单元测试 #第行;第行 #给出如下类定义:publicclasstest{test(intk){}}如果要创建一个该类的对象,正确的语句是:Atestobj=newtest();Btestobj=newtest();Ctestobj=newtest(&#;&#;);Dtestobj=newtest(.); #编译Java源程序文件将产生相应的字节码文件,字节码文件的扩展名为?AjavaBclassChtmlDexe #编译和运行以下代码的结果为:publicclassMyMain{publicstaticvoidmain(Stringargv){System.out.println(&#;Hellocruelworld&#;);}}A编译错误B运行输出&#;Hellocruelworld&#;C编译无错,但运行时指示没有定义构造方法D编译无错,但运行时指示找不到main方法 #编译无错,但运行时指示找不到main方法 #编译通过,执行结果为:x= #网课答案 #考虑如下类:publicclassTest{intj,k;publicTest(intj){this(j,);}publicTest(intj,intk){this.j=j;this.k=k;}}以下哪些可正确创建Test对象 #要产生[,]之间的随机整数使用哪个表达式 #设有如下代码:int[]x=newint[];执行后,以下哪个说法正确 #输出: #输出:True #输出##### #输出valueis. #错第二章单元测试