1)The "less than or equal to" comparison operator in Java is ________.
A)<< B) != C) =< D) <= E) <

2)The equal comparison operator in Java is ________.
A)!= B) <> C) ^= D) ==  

3)What is 1 + 1 + 1 + 1 + 1 == 5?
A)true  B)false  C)There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

4)What is 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0?   _______
A)true  B)false  C)There is no guarantee that 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0 is true.

浮点数不能直接使用==进行比较

5)In Java, the word true is ________.   
A)same as value 0  B) a Boolean literal  C)a Java keyword  D) same as value 1

6)________ is the code with natural language mixed with Java code.   
A)A flowchart diagram  B) Java program  C)A Java statement  D) Pseudocode   

flowchart diagram 流程图

Pseudocode   伪代码

7)Which of the following code displays the area of a circle if the radius is positive?   
A)if (radius <= 0) System.out.println(radius * radius * 3.14159);
B)if (radius > 0) System.out.println(radius * radius * 3.14159);
C)if (radius >= 0) System.out.println(radius * radius * 3.14159);
D)if (radius != 0) System.out.println(radius * radius * 3.14159);

8)Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?

if (x > 0)
if (y > 0)
System.out.println("x > 0 and y > 0");
else if (z > 0)
System.out.println("x < 0 and z > 0");

A)x > 0 and y > 0; B) x < 0 and z < 0; C)x < 0 and z > 0; D) no printout.

9)Analyze the following code:

boolean even = false;
if (even = true) {
System.out.println("It is even!");
}

A)The program has a runtime error.
B)The program runs fine, but displays nothing.
C)The program has a compile error.
D)The program runs fine and displays It is even!.

注意这里是赋值=号!!!

10)Analyze the following code.

boolean even = false;
if (even) {
System.out.println("It is even!");
}

A)The code is wrong. You should replace if (even) with if (even == true)
B)The code is wrong. You should replace if (even) with if (even = true)
C)The code displays nothing.
D)The code displays It is even!

11)The following code displays ________.

double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");

A)too cold  B) just right  C)too hot too cold just right  D) too hot

12)Analyze the following code:
Code 1:

boolean even;
if (number % 2 == 0)
even = true;
else
even = false;

Code 2:

boolean even = (number % 2 == 0); 

A)Code 1 has compile errors.
B)Both Code 1 and Code 2 are correct, but Code 2 is better.
C)Both Code 1 and Code 2 have compile errors.
D)Code 2 has compile errors.

13)Suppose income is 4001, what is the output of the following code:

if (income > 3000) {
System.out.println("Income is greater than 3000");
}
else if (income > 4000) {
System.out.println("Income is greater than 4000");

A)no output
B)Income is greater than 3000  
C)Income is greater than 4000 followed by Income is greater than 3000
D)Income is greater than 3000 followed by Income is greater than 4000
E)Income is greater than 4000

14)The ________ method immediately terminates the program.
A)System.halt(0); B)System.quit(0); C)System.terminate(0); D)System.stop(0); E)System.exit(0);

15)Which of the Boolean expressions below is incorrect? (Choose all that apply.)
A)(x != 0) || (x = 0)
B)(true) && (3 => 4)
C)(-10 < x < 0)
D)!(x > 0) && (x > 0)
E)(x > 0) || (x < 0)

16)Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
A)((x < 100) && (x > 1)) && (x < 0)
B)1 < x < 100 && x < 0
C)(1 > x >  100) || (x < 0)
D)((x < 100) && (x > 1)) || (x < 0)

17)Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)?  
A)9 B) 11 C) 10

18)Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10)?
A)11 B) 10 C) 9

19)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x-- > 10)?
A)11 B) 9 C) 10

20)Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10)?
A)10 B) 9 C) 11

21)To check whether a char variable ch is an uppercase letter, you write ________.
A)('A' <= ch <= 'Z') B) (ch >= 'A' || ch <= 'Z')
C)(ch >= 'A' && ch <= 'Z') D) (ch >= 'A' && ch >= 'Z')

22)Analyze the following code:

if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");

A)The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println(…) statement must be put inside a block.
B)The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.
C)The statement compiles fine.
D)The statement compiles fine, but has a runtime error.

23)What is the output of the following code?

char ch = 'F';
if (ch >= 'A' && ch <= 'Z')
System.out.println(ch);

A)f B) F C) F f D) nothing

24)What is y after the following switch statement is executed(执行)?

x = 3;
switch (x + 3) {
case 6: y = 0;
case 7: y = 1;
default: y += 1;
}

A)4 B) 3 C) 1 D) 2

注意:这里的swich语句中没有break

25)What is the printout of the following switch statement?

char ch = 'a';
switch (ch) {
case 'a':
case 'A':
System.out.print(ch); break;
case 'b':
case 'B':
System.out.print(ch); break;
case 'c':
case 'C':
System.out.print(ch); break;
case 'd':
case 'D':
System.out.print(ch);
}

A)a B) abc C) abcd D) aa E) ab

26)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);
}

A)abcd B) bb C) bcd D) bbb E) b

注意这里case中没有break

27)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;
}

A)The program has a compile error because the required default case is missing in the switch statement.
B)The switch control variable cannot be double.
C)The program has a compile error because the required break statement is missing in the switch statement.
D)No errors.

double类型的浮点数只能用一个范围来判断,不能将其具体到一个准确的数字上。

28)What is y after the following statement is executed?

x = 0;
y = (x > 0) ? 10 : -10;

A)0
B)-10
C)10
D)20
E)Illegal expression

29)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;

A)All three are correct, but Code 1 is preferred.
B)All three are correct, but Code 3 is preferred.
C)All three are correct, but Code 2 is preferred.
D)Code 3 has a compile error, because you attempt to assign number to even.
E)Code 2 has a compile error, because you cannot have true and false literals in the conditional expression.

30)What is the output of the following code?

boolean even = false;
System.out.println((even ? "true" : "false"));

A)false  B) true  C)true false  D) nothing

31)Which of the following are valid specifiers for the printf statement? (Choose all that apply.)
A)%4c  B)%10.2e C)%10b D)%6d E)%8.2d

%c 字符输出  %e 标准科学记数法形式的数  %d 十进制整数输出

32)The statement System.out.printf("%3.1f", 1234.56) outputs ________.
A)1234.6  B)123.5  C)123.4  D)1234.56  E)1234.5

%3.1f 要输出的浮点数至少三位,其中小数部分一位

33)The statement System.out.printf("%3.1e", 1234.56) outputs ________.  
A)0.1e+04  B)0.123456e+04  C)0.123e+04  D)1.23+03  E)1.2e+03

科学计数法的表示,只保留一位整数

34)The statement System.out.printf("%5d", 123456) outputs ________.  
A)12345.6 B) 123456 C) 12345  D) 23456

35)The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space)   
A)23456***** B) 123456****  C)****123456 D) 12345*****

%10s 输出的字符串至少10个字符,如果小于10个字符,就在该字符串前加空格

36)Analyze the following code:
int i = 3434; double d = 3434;
System.out.printf("%5.1f %5.1f", i, d);
A)The code compiles and runs fine to display 3434 3434.0.
B)The code compiles and runs fine to display 3434.0 3434.0.
C)i is an integer, but the format specifier %5.1f specifies a format for double value. The code has an error.

37)The order of the precedence(优先级) (from high to low) of the operators +, *, &&, ||, & is:  ______
A)&, ||, &&, *, +
B)&&, ||, &, *, +
C)*, +, &, ||, &&
D)*, +, &&, ||, &
E)*, +, &, &&, ||

38)Which of the following operators are right-associative(右结合)?   
A)= B) * C) % D) + E) &&

39)What is the value of the following expression?
true || true && false   
A)true B) false

40)Which of the following statements are true? (Choose all that apply.)
A)(x > 0 || x < 10) is same as ((x > 0) || (x < 10))
B)(x > 0 && x < 10) is same as ((x > 0) && (x < 10))
C)(x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 && y < 0))  
D)(x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) && y < 0)

&&条件与的优先级precendence要高于||条件或

Java题库——Chapter3 操作符、选择的更多相关文章

  1. Java题库——Chapter13抽象类和接口

    )What is the output of running class Test? public class Test { public static void main(String[ ] arg ...

  2. Java题库——Chapter8 对象和类

    1)________ represents an entity(实体) in the real world that can be distinctly identified. 1) _______ ...

  3. JAVA题库01

    说出一些常用的类,包,接口,请各举5个 常用的类:BufferedReader  BufferedWriter  FileReader  FileWirter  String Integer java ...

  4. Java题库——Chapter17 二进制I/0

    Introduction to Java Programming 的最后一章,完结撒花!Chapter 17 Binary I/O Section 17.2 How is I/O Handled in ...

  5. Java题库——Chapter16 JavaFX UI组件和多媒体

    Chapter 16 JavaFX UI Controls and Multimedia Section 16.2 Labeled and Label1. To create a label with ...

  6. Java题库——Chapter14 JavaFX基础

    Chapter 14 JavaFX Basics Section 14.2 JavaFX vs Swing and AWT1. Why is JavaFX preferred?a. JavaFX is ...

  7. Java题库——Chapter12 异常处理和文本IO

    异常处理 1)What is displayed on the console when running the following program? class Test { public stat ...

  8. Java题库——Chapter11 继承和多态

    1)Analyze the following code: public class Test { public static void main(String[ ] args) { B b = ne ...

  9. Java题库——Chapter10 面向对象思考

    1)You can declare two variables with the same name in ________. 1) _______ A)a method one as a forma ...

随机推荐

  1. NodeJS4-6静态资源服务器实战_range范围请求

    range范围请求:向服务器发起请求可以申明我想请求判断内容的范围,从多少个字节到多少个字节,一次要求把所有的内容拿回来,服务器在得到相应的请求之后,从拿到对应的文件,拿到对应的字节返回给客户端.要实 ...

  2. Python与线性代数基本概念

    在Python中使用Numpy创建向量: x = np.array([1, 2, 3, 4]) 创建3 x 3矩阵 B = np.array([[1, 2],[3, 4],[5, 6]]) Shape ...

  3. JavaScript图形实例:七彩线团

    1.线团图案 设立坐标计算公式为: X=R1*COS(3α)+R2*COS(14α)) Y=R1*SIN(3α)+R2 *SIN(14α)) 再用循环依次取α值为0~2π(每次增量为0.01),计算出 ...

  4. Internet History,Technology,and Security -Transport Control Protocol(TCP)(Week6)

    Week6 Technology: Transport Control Protocol(TCP) Welcome to Week 6 of IHTS. We are in our second we ...

  5. Newifi D1或 D2在Openwrt中,启用硬件NAT,启用BBR

    Newifi D1或 D2在Openwrt中,启用硬件NAT,启用BBR 转载注明来源: 本文链接 来自osnosn的博客,写于 2019-09-27. 启用 mt7621的硬件nat (Newifi ...

  6. 提升代码幸福度,五个技巧减少js开发中的if else语句

     壹 ❀ 引 在JavaScript开发中,条件判断语句的使用频率是极高的,而对于条件判断简单易读的if else应该都是大家的首选.可是代码写的久了,我们总是希望自己的代码看着能更为简洁规范(逼格更 ...

  7. IT兄弟连 HTML5教程 DIV+CSS网站首页布局示例

    首页的设计直接影响网站的整体形象,虽然没有一个统一的规范,但最好将其设计为大众化的,只要信息内容能够合理地编排即可,使用户可以方便地找到需要的信息.另外,首页的高度最好不要超过三个屏幕,页面中使用的颜 ...

  8. 如何安装 IntelliJ IDEA 最新版本——详细教程

    IntelliJ IDEA 简称 IDEA,被业界公认为最好的 Java 集成开发工具,尤其在智能代码助手.代码自动提示.代码重构.代码版本管理(Git.SVN.Maven).单元测试.代码分析等方面 ...

  9. 解密国内BAT等大厂前端技术体系-腾讯篇(长文建议收藏)

    1 引言 为了了解当前前端的发展趋势,让我们从国内各大互联网大厂开始,了解他们的最新动态和未来规划.这是解密大厂前端技术体系的第三篇,前两篇已经讲述了阿里和百度在前端技术这几年的技术发展.这一篇从腾讯 ...

  10. C#通用查询器

    很多通用查询器,对查询条件中的AND及OR的支持度不是很好,要么全部是AND要么全部是OR.笔者通过一段时间的摸索,终于完成了一个自己较为满意的通用查询器, 可以实现多条件的AND及OR,现将实现过程 ...