JAVA练习题含答案-answers to practice 2

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Multiple Choice

1)Which operator is used to concatenate two strings?

(a)+

(b)–

(c)*

(d)/

Answer: A (see page 35)

2)Which operator returns the remainder of integer division?

(a)%

(b)/

(c)*

(d)none of the above

Answer: A (see page 26)

3)What is the value of the variable c in the statements that follow?

String phrase = "Make hay while the sun is shining.";

char c = phrase.charAt(10);

(a)w

(b)h

(c)i

(d)None of the above

Answer: B (see page 40)

4)The escape sequence the represents the new-line character is:

(a)\r

(b)\t

(c)\n

(d)\\

Answer: C (see page 43)

5)The syntax that declares a Java named constant named SALES_TAX is:

(a)double SALES_TAX = 7.50;

(b)public double SALES_TAX = 7.50;

(c)public static double SALES_TAX = 7.50;

(d)public static final double SALES_TAX = 7.50;

Answer: D (see page 47)

6)In Java, a block comment is delimited by:

(a)*/ /*

(b)/* /*

(c)/* */

(d)*/ */

Answer: C (see page 50)

7)To mark a block comment for inclusion in the Javadoc documentation, the block must be

delimited by:

(a)/** */

(b)*/* */

(c)**/ /*

(d)**/ */

Answer: A (see page 50)

8)Valid arguments to the System.out object‟s println method include:

(a) “Anything with double quotes”

(b) String variables

(c) Variables of type int

(d) All of the above

Answer: D (see page 59)

9)Which statement or group of statements produces the output: Java programming is fun!

(a)System.out.print(Java programming);

System.out.print(is fun!);

(b)System.out.println(Java programming is fun!);

(c)System.out.println(“Java programming”);

System.out.println(“ is fun!”);

(d)System.out.print(“Java programming”)

System.out.println(“ is fun!”);

Answer: D (see page 60)

10)If a hyphen is added after the % in a format specifier, the output will be _________.

(a)Left justified

(b)Right justified

(c)Centered

(d)None of the above

Answer: A (see page 64)

11)The statement: System.out.printf("%6.2f", 597.7231); displays:

(a)597.723

(b)597.72

(c)000597.72

(d)None of the above

Answer: B (see page 64)

12)The Java method printf is based on the ________ language.

(a)Pascal

(b)C++

(c)C

(d)ADA

Answer: C (see page 67)

13)The class NumberFormat allows you to specify a constant representing which country‟s

currency format should be used. To use this constant you must import:

(a)java.util.Locale

(b)java.util.Currency

(c)java.util.Properties

(d)None of the above.

Answer: A (see page 71)

14)Standard code libraries in Java are called:

(a)Methods

(b)Classes

(c)Packages

(d)Statements

Answer: C (see page 72)

15)What Java package includes the class Scanner?

(a)awt

(b)swing

(c)io

(d)util

Answer: D (see page 78)

相关文档
最新文档