教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 实用模板 >

Java练习题1(有答案)(4)

来源:网络收集 时间:2026-01-29
导读: System.out.print(ch); break; case c : case C : System.out.print(ch); break; case d : case D : System.out.print(ch); } 1、 abcd 2、 a 3、 aa 4、 ab 5、 abc 答案 2 第 47题 What is the printout of the f

System.out.print(ch); break; case c : case C :

System.out.print(ch); break; case d : case D : System.out.print(ch); }

1、 abcd 2、 a 3、 aa

4、 ab 5、 abc 答案 2 第 47题 What is the printout of the following switch statement? char ch = b ; switch

(ch)

{ case a :

System.out.print(ch); case b :

System.out.print(ch); case c :

System.out.print(ch); case d :

System.out.print(ch); }

1、 abcd 2、 bcd 3、 b 4、 bb

5、 bbb 答案 5 第 48题 Analyze the following program fragment: int x; double d = 1.5; switch (d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0: x = 3; }

1、 The program has a compile error because the required break statement is missing in the switch statement.

2、 The program has a compile error because the required default case is missing in the switch statement.

3、 The switch control variable cannot be double.

4、 No errors. 答案 3

第 49题 Analyze the following code fragments that assign a boolean value to the variable even. Code 1: if (number % 2 == 0) even = true; else even = false; Code 2:

even = (number % 2 == 0) ? true: false; Code 3: even = number % 2 == 0;

1、 Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.

2、 Code 3 has a compile error, because you attempt to assign number to even.

3、 All three are correct, but Code 1 is preferred. 4、 All three are correct, but Code 2 is preferred. 5、 All three are correct, but Code 3 is preferred.

答案 5 第 50题 The statement System.out.printf(\1234.56) outputs ___________. 1、 0.1e+04 2、 0.123456e+04 3、 0.123e+04

4、 1.2e+03 5、 1.23+03 答案 4 第 51题 Analyze the following code: int i = 3434; double d = 3434; System.out.printf(\

1、 The code compiles and runs fine to display 3434.0 3434.0. 2、 The code compiles and runs fine to display 3434 3434.0.

3、 i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

答案 3 第 52题 What is the value of the following expression?

true || true && false 1、 true

2、 false 答案 1 第 53题 Which of the following statements are true? 1、 (x > 0 && x < 10) is same as ((x > 0) && (x < 10))

2、 (x > 0 || x < 10) is same as ((x > 0) || (x < 10))

3、 (x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0)) 4、 (x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0) 答案 1 2 3 第 54题 How many times will the following code print \ int count = 0; while (count < 10) {

System.out.println(\count++; } 1、 8 2、 9 3、 10

4、 11 5、 0 答案 3 第 55题 Analyze the following code. int count = 0; while (count < 100) { // Point A

System.out.println(\count++; // Point B }

// Point C

1、 count < 100 is always true at Point A 2、 count < 100 is always true at Point B 3、 count < 100 is always false at Point B

4、 count < 100 is always true at Point C 5、 count < 100 is always false at Point C 答案 1 5 第 56题 How many times will the following code print \ int count = 0; do {

System.out.println(\ } while (count++ < 10); 1、 8 2、 9 3、 10

to

Java!\

to

Java\

4、 11 5、 0 答案 4 第 57题 What is the value in count after the following loop is executed? int count = 0; do {

System.out.println(\ } while (count++ < 9); System.out.println(count); 1、 8 2、 9 3、 10

4、 11 5、 0 答案 3 第 58题 Do the following two statements in (I) and (II) result in the same value in sum? (I): for (int i = 0; i<10; ++i) { sum += i;

} (II): for (int i = 0; i<10; i++) { sum += i; }

1、 Yes 2、 No 答案 1 第 59题 Is the following loop correct? for (; ; ); 1、 Yes 2、 No 答案 1 第 60题 Analyze the following code: public class Test { public static void main (String args[]) { int i = 0; for

(i

=

0;

i

<

10;

i++);

System.out.println(i + 4); } }

1、 The program has a compile error because of the semicolon (;) on the for loop line.

2、 The program compiles despite the semicolon (;) on the for loop line, and displays 4.

3、 The program compiles despite the semicolon (;) on the for loop line, and displays 14.

4、 The for loop in this program is same as for (i = 0; i < 10; i++) { }; System.out.println(i + 4); 答案 3 4

…… 此处隐藏:1226字,全部文档内容请下载后查看。喜欢就下载吧 ……
Java练习题1(有答案)(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/521351.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)