大学MOOC 面向对象程序设计(java)(东华理工大学)1450291372 最新慕课完整章节测试答案
第2章 数据类型与表达式
第2章的单元测验
1、单选题:
一个 int 类型的整数和一个 double 类型的数进行加法运算,则结果类型为
选项:
A: int
B: double
C: float
D: long
答案: 【 double】
2、单选题:
设 a = 8,则表达式 a >>> 2 的值是
选项:
A: 16
B: 2
C: 8
D: 4
答案: 【 2】
3、单选题:
用八进制表达 8 的值,正确的是?
选项:
A: 0x10
B: 010
C: 08
D: 0x8
答案: 【 010】
4、单选题:
要产生[20,999]之间的随机整数使用( )表达式。
选项:
A: (int)(20+Math.random()*979)
B: 20+(int)(Math.random()*980)
C: (int)Math.random()*999
D: 20+(int)Math.random()*980
答案: 【 20+(int)(Math.random()*980)】
5、单选题:
表达式 1+2+ "x"+3 的值是
选项:
A: "12x3"
B: "3x3"
C: "6x"
D: "x6"
答案: 【 "3x3"】
6、单选题:
整型变量a,b的值定义如下: int a = 21; int b = 22;则表达式 ++a == b++ 的值为:
选项:
A: false
B: 21
C: true
D: 22
答案: 【 true】
7、单选题:
下列叙述中,正确的是?
选项:
A: 声明变量时必须指定一个类型
B: java认为变量number与Number相同
C: Java中唯一的注释方式是"//"
D: 一个源文件中public类可以有0或多个
答案: 【 声明变量时必须指定一个类型】
8、单选题:
以下数据类型转换中,必须进行强制类型转换的是
选项:
A: int→char
B: short→long
C: float→double
D: int→double
答案: 【 int→char】
9、单选题:
以下程序的运行结果为class test { public static void main(String args[]) { int x=2; System.out.printf("%d,%d,%d", x++ , x, ++x); }}
选项:
A: 3,3,3
B: 2,3,4
C: 2,2,3
D: 3,3,4
答案: 【 2,3,4】
10、单选题:
以下哪个方法的调用结果是整数类型的结果3
选项:
A: Math.ceil(3.1)
B: Math.floor(2.7)
C: Math.abs(3.1)
D: Math.round(2.7)
答案: 【 Math.round(2.7)】
11、多选题:
下列选项中( )是合法的 Java 标识符名字。
选项:
A: $index
B: name-7
C: _byte
D: char
答案: 【 $index;
_byte】
12、多选题:
下面各项中定义变量及赋值正确的有( )。
选项:
A: int i = 32;
B: float f = 45.0;
C: double d = 45.0;
D: long x = (long)45.0;
答案: 【 int i = 32;;
double d = 45.0; ;
long x = (long)45.0;】
13、多选题:
设有类型定义 int x=24;long y=25;下列赋值语句正确的是
选项:
A: y=x;
B: x=y;
C: x=(int)y;
D: y=x+2;
答案: 【 y=x; ;
x=(int)y;;
y=x+2;】
14、多选题:
以下变量定义和初始化中哪些编译正确?
选项:
A: short myshort = 99S;
B: String name = 'Excellent tutorial Mr Green';
C: char c = 17;
D: int z = 015;
答案: 【 char c = 17;;
int z = 015;】
15、填空题:
思考程序段对应的运行结果int a = 2;System.out.print( a++);
答案: 【 2】
16、填空题:
写出程序段对应的运行结果int x = 4;System.out.print( "x=" +((x > 4) ? 99.99 : 9));
答案: 【 x=9.0】
17、填空题:
写出程序段对应的输出结果int x = 125;System.out.print(x/10);
答案: 【 12】
18、填空题:
写出程序段对应的运行结果int x = 125;System.out.print(x%3==0);
答案: 【 false】
19、填空题:
在Java中int类型变量占用空间是4个字节,char类型变量分配空间是 ( )个字节
答案: 【 2##%_YZPRLFH_%##两】
第3章 流程控制语句
第3章单元测验
1、单选题:
以下程序的运行结果为( )。public class Test { public static void main(String args[ ]) { int i=0, j=2; do { ++i; j--; } while(j>0); System.out.println(i); }}
选项:
A: 0
B: 1
C: 2
D: 3
答案: 【 2】
2、单选题:
执行以下程序后,输出结果为( )。public class Ex2{ public static void main(String args[ ]) { int k ,f=1; for (k=2;k<5;k++) f = f * k; System.out.println(k); }}
选项:
A: 1
B: 4
C: 5
D: 24
答案: 【 5】
3、单选题:
设有如下类:class Loop{ public static void main(String[ ] args) { int x=0;int y=0; outer: for(x=0;x<100;x++){ middle: for(y=0;y<100;y++){ System.out.println("x="+x+"; y="+y); if (y==10) { <<<insert code>>> } } } }}在<<<insert code>>>处插入什么代码可以结束外循环?
选项:
A: continue middle;
B: break outer;
C: break middle;
D: continue outer;
答案: 【 break outer;】
4、单选题:
以下循环的执行次数是( )。int x=4,y=2;while (--x!=x/y) { }
选项:
A: 1
B: 2
C: 3
D: 4
答案: 【 3】
5、单选题:
以下程序段的输出结果为( )。int x=1;for (x=2;x<=10;x++ ) ;System.out.print(x);
选项:
A: 1
B: 2
C: 10
D: 11
答案: 【 11】
6、单选题:
设 int x=2,y=3,则表达式(y-x==1)?(!true?1:2):(false?3:4)的值为( )。
选项:
A: 1
B: 2
C: 3
D: 4
答案: 【 2】
7、单选题:
以下程序段对应的运行结果为?int j = 1;while(j<5 ){if(j == 1) continue; j++;System.out.print(j);}
选项:
A: 1
B: 234
C: 无限循环
D: 2345
答案: 【 无限循环】
8、单选题:
若a的值为3时,下列程序段被执行后,c的值是多少? int c = 1; if ( a>0 ) if ( a>3 ) c = 2; else c = 3; else c = 4;
选项:
A: 2
B: 3
C: 1
D: 4
答案: 【 3】
9、单选题:
以下程序的运行结果为public class test { public static void main(String args[]) { int i = 1; do { i--; } while (i > 2); System.out.print(i); }}
选项:
A: 1
B: 2
C: -1
D: 0
答案: 【 0】
10、多选题:
outer: for( int i =1; i<3 ;i++) { inner : for ( j= 1;j<3;j++) { if (j==2) continue outer: System.out.prinltn("i= " + i ",j = " + j) } } 该代码段的输出结果含有?
选项:
A: i= 1,j= 1
B: i= 1,j= 2
C: i= 2,j= 1
D: i= 2,j= 2
答案: 【 i= 1,j= 1 ;
i= 2,j= 1】
11、多选题:
设有如下代码段, x为哪些数时输出内容中含有 "Test2" ? switch (x) { case 1 : System.out.println("Test1"); case 2 : case 3 : System.out.println("Test2"); break; } System.out.println("Test3");
选项:
A: 0
B: 1
C: 2
D: 3
答案: 【 1;
2;
3】
12、填空题:
写出以下程序段对应的运行结果String c="red";switch (c) { default: System.out.print("white"); break; case "red": System.out.print("red");
