chapter 3 selections.docx
TRANSCRIPT
-
8/9/2019 Chapter 3 Selections.docx
1/16
Chapter 3 Selections
Section 3.2 boolean Data Type
3.1 The "less than or equal to" comparison operator in Java is __________.A. <
B.
-
8/9/2019 Chapter 3 Selections.docx
2/16
C. same as value
D. same as value (
Sections 3.3-3.10
3.6 hich o& the &ollo+in' co,e ,isplas the area o& a circle i& the ra,ius is positive.A. i& /ra,ius != (0 1stem.out.println/ra,ius 2 ra,ius 2 3.4$506
B. i& /ra,ius >= (0 1stem.out.println/ra,ius 2 ra,ius 2 3.4$506
C. i& /ra,ius > (0 1stem.out.println/ra,ius 2 ra,ius 2 3.4$506
D. i& /ra,ius
-
8/9/2019 Chapter 3 Selections.docx
3/16
D. The pro'ram runs an, ,isplas )t is even!.
3.9 1uppose is;rime is a :oolean varia:le* +hich o& the &ollo+in' is the correct an, :est statement &or
testin' i& is;rime is true.
A. i& /is;rime = true0
B. i& /is;rime == true0
C. i& /is;rime0
D. i& /!is;rime = &alse0
E. i& /!is;rime == &alse0
3.10 hat is the output o& the &ollo+in' co,e%
int 7 = (6
i& /7 < 40
7 = 7 # 6
1stem.out.println/"7 is " # 706
A. 7 is (
B. 7 is
C. 7 is ?
D. 7 is 3
E. 7 is 4
3.11 Anal9e the &ollo+in' co,e.
:oolean even = &alse6
i& /even0
1stem.out.println/")t is even!"06
A. The co,e ,isplas )t is even!
B. The co,e ,isplas nothin'.
C. The co,e is +ron'. @ou shoul, replace i& /even0 +ith i& /even == true0
-
8/9/2019 Chapter 3 Selections.docx
4/16
D. The co,e is +ron'. @ou shoul, replace i& /even0 +ith i& /even = true0
3.12 The &ollo+in' co,e ,isplas ___________.
,ou:le temperature = $(6
i& /temperature >= ((0
1stem.out.println/"too hot"06else i& /temperature
-
8/9/2019 Chapter 3 Selections.docx
5/16
3.14 1uppose income is 4((* +hat is the output o& the &ollo+in' co,e
i& /income > 3(((0
1stem.out.println/")ncome is 'reater than 3((("06
else i& /income > 4(((0
1stem.out.println/")ncome is 'reater than 4((("06
A. no output
B. )ncome is 'reater than 3(((
C. )ncome is 'reater than 3((( &ollo+e, : )ncome is 'reater than 4(((
D. )ncome is 'reater than 4(((
E. )ncome is 'reater than 4((( &ollo+e, : )ncome is 'reater than 3(((
3.15 The __________ metho, imme,iatel terminates the pro'ram.A. 1stem.terminate/(06
B. 1stem.halt/(06
C. 1stem.e7it/(06
D. 1stem.quit/(06
E. 1stem.stop/(06
3.16 1uppose ou +rite the co,e to ,ispla "Cannot 'et a ,rivers license" i& a'e is less than
an, "Can 'et a ,rivers license" i& a'e is 'reater than or equal to .
hich o& the &ollo+in' co,e is correct%
)
i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06i& /a'e >= 0
1stem.out.println/"Can 'et a ,rivers license"06
))
i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06else
1stem.out.println/"Can 'et a ,rivers license"06
-
8/9/2019 Chapter 3 Selections.docx
6/16
)))i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06
else i& /a'e >= 01stem.out.println/"Can 'et a ,rivers license"06
)i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06
else i& /a'e > 01stem.out.println/"Can 'et a ,rivers license"06
else i& /a'e == 0
1stem.out.println/"Can 'et a ,rivers license"06
A. )
B. ))
C. )))
D. )
3.17 1uppose ou +rite the co,e to ,ispla "Cannot 'et a ,rivers license" i& a'e is less than an,
"Can 'et a ,rivers license" i& a'e is 'reater than or equal to .hich o& the &ollo+in' co,e is the :est%
)
i& /a'e < 01stem.out.println/"Cannot 'et a ,rivers license"06
i& /a'e >= 01stem.out.println/"Can 'et a ,rivers license"06
))i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06
else
1stem.out.println/"Can 'et a ,rivers license"06
)))i& /a'e < 01stem.out.println/"Cannot 'et a ,rivers license"06
else i& /a'e >= 0
1stem.out.println/"Can 'et a ,rivers license"06
)i& /a'e < 0
1stem.out.println/"Cannot 'et a ,rivers license"06
else i& /a'e > 0
-
8/9/2019 Chapter 3 Selections.docx
7/16
1stem.out.println/"Can 'et a ,rivers license"06else i& /a'e == 0
1stem.out.println/"Can 'et a ,rivers license"06
A. )
B. ))
C. )))
D. )
1ections 3.83.33.18 hich o& the Boolean e7pressions :elo+ is incorrect%
A. /true0 FF /3 => 40
B. !/7 > (0 FF /7 > (0
C. /7 > (0 GG /7 < (0
D. /7 != (0 GG /7 = (0
E. /8( < 7 < (0
3.19 hich o& the &ollo+in' is the correct e7pression that evaluates to true i& the num:er 7 is :et+een
an, (( or the num:er is ne'ative%
A. < 7 < (( FF 7 < (
B. //7 < ((0 FF /7 > 00 GG /7 < (0
C. //7 < ((0 FF /7 > 00 FF /7 < (0
D. / > 7 > ((0 GG /7 < (0
3.20 Assume 7 = 4 an, = $* hich o& the &ollo+in' is true%
A. 7 < $ FF < $
B. 7 < $ GG < $
C. 7 > $ FF > $
D. 7 > $ GG > $
-
8/9/2019 Chapter 3 Selections.docx
8/16
3.21 Assume 7 = 4* hich o& the &ollo+in' is true%A. !/7 == 40
B. 7 != 4
C. 7 == $
D. 7 != $
3.22 Assume 7 = 4 an, = $* hich o& the &ollo+in' is true%
A. !/7 == 0
B. 7 !=
C. 7 ==
D. 7 >=
3.23 hich o& the &ollo+in' is equivalent to 7 != %
A. ! /7 == 0
B. 7 > FF 7 <
C. 7 > GG 7 <
D. 7 >= GG 7 (0 FF /7## > (0.
A. 5
B. (
C.
3.26 1uppose 7=( an, =( +hat is 7 a&ter evaluatin' the e7pression / >= (0 GG /788 > (0.
-
8/9/2019 Chapter 3 Selections.docx
9/16
A. 5
B. (
C.
3.27 1uppose 7=( an, =( +hat is 7 a&ter evaluatin' the e7pression / >= (0 GG /7## > (0.
A. 5
B. (
C.
3.28 To chec- +hether a char varia:le ch is an uppercase letter* ou +rite ___________.
A. /ch >= A FF ch >= H0
B. /ch >= A FF ch = A GG ch = A FF ch
-
8/9/2019 Chapter 3 Selections.docx
10/16
A. I
B. &
C. nothin'
D. I &
1ection 3.4 s+itch 1tatements
3.31 hat is a&ter the &ollo+in' s+itch statement is e7ecute,%
int 7 = 36 int = 46s+itch /7 # 30
case = (6
case = 6 ,e&ault #= 6
A.
B. ?
C. 3
D. 4
E. (
-
8/9/2019 Chapter 3 Selections.docx
11/16
3.32 hat +ill :e ,isplae, : the &ollo+in' s+itch statement%
char ch = a6
s+itch /ch0 case a
case A
1stem.out.print/ch06 :rea-6 case :
case B
1stem.out.print/ch06 :rea-6 case c
case C
1stem.out.print/ch06 :rea-6
case , case D
1stem.out.print/ch06
A. a:c,
B. a
C. aa
D. a:
E. a:c
3.33 hat +ill :e ,isplae, : the &ollo+in' s+itch statement%
char ch = :6
s+itch /ch0 case a
1stem.out.print/ch06
case : 1stem.out.print/ch06
case c
1stem.out.print/ch06
case , 1stem.out.print/ch06
A. a:c,
B. :c,
-
8/9/2019 Chapter 3 Selections.docx
12/16
C. :
D. ::
E. :::
3.34 Anal9e the &ollo+in' pro'ram &ra'ment
int 76,ou:le , = .$6
s+itch /,0 case .( 7 = 6
case .$ 7 = ?6
case ?.( 7 = 36
A. The pro'ram has a compile error :ecause the require, :rea- statement is missin' in the s+itch
statement.
B. The pro'ram has a compile error :ecause the require, ,e&ault case is missin' in the s+itch
statement.
C. The s+itch control varia:le cannot :e ,ou:le.
D. Ko errors.
1ection 3.$ Con,itional E7pressions3.35 hat is a&ter the &ollo+in' statement is e7ecute,%
7 = (6 = /7 > (0 % ( 8(6
A. 8(
B. (
C. (
D. ?(
E. )lle'al e7pression
3.36 Anal9e the &ollo+in' co,e &ra'ments that assi'n a :oolean value to the varia:le even.
Co,e
-
8/9/2019 Chapter 3 Selections.docx
13/16
i& /num:er ? == (0 even = true6
else
even = &alse6
Co,e ?
even = /num:er ? == (0 % true &alse6
Co,e 3
even = num:er ? == (6
A. Co,e ? has a compile error* :ecause ou cannot have true an, &alse literals in the con,itional
e7pression.
B. Co,e 3 has a compile error* :ecause ou attempt to assi'n num:er to even.
C. All three are correct* :ut Co,e is pre&erre,.
D. All three are correct* :ut Co,e ? is pre&erre,.
E. All three are correct* :ut Co,e 3 is pre&erre,.
3.37 hat is the output o& the &ollo+in' co,e% :oolean even = &alse6
1stem.out.println//even % "true" "&alse"006
A. true
B. &alse
C. nothin'
D. true &alse
1ection 3. Iormattin' Console Lutput an, 1trin's3.38 hich o& the &ollo+in' are vali, speci&iers &or the print& statement%
A. 4c
B. (:
C. ,
D. M.?,
-
8/9/2019 Chapter 3 Selections.docx
14/16
E. (.?e
3.39 The statement 1stem.out.print&/"3.&"* ?34.$0 outputs ___________.
A. ?3.4
B. ?3.$
C. ?34.$
D. ?34.$
E. ?34.
3.40 The statement 1stem.out.print&/"3.e"* ?34.$0 outputs ___________.
A. (.e#(4
B. (.?34$e#(4
C. (.?3e#(4
D. .?e#(3
E. .?3#(3
3.41 The statement 1stem.out.print&/"$,"* ?34$0 outputs ___________.
A. ?34$
B. ?34$
C. ?34$
D. ?34$.
3.42 The statement 1stem.out.print&/"(s"* "?34$"0 outputs ___________. /Kote 2 represents a
space0
A. ?34$2222
B. ?34$22222
C. ?34$22222
D. 2222?34$
-
8/9/2019 Chapter 3 Selections.docx
15/16
3.43 1uppse num:er contains inte'er value 4* +hich o& the &ollo+in' statement is correct%A. 1stem.out.print&/"3, 4,"* num:er* Nath.po+/num:er* .$006
B. 1stem.out.print&/"3, 4.?,"* num:er* Nath.po+/num:er* .$006
C. 1stem.out.print&/"3, 4.?&"* num:er* Nath.po+/num:er* .$006
D. 1stem.out.print&/"3& 4.?,"* num:er* Nath.po+/num:er* .$006
E. 1stem.out.print&/"3& 4.?&"* num:er* Nath.po+/num:er* .$006
3.44 Anal9e the &ollo+in' co,e
int i = 34346 ,ou:le , = 34346
1stem.out.print&/"$.& $.&"* i* ,06
A. The co,e compiles an, runs &ine to ,ispla 3434.( 3434.(.
B. The co,e compiles an, runs &ine to ,ispla 3434 3434.(.
C. i is an inte'er* :ut the &ormat speci&ier $.& speci&ies a &ormat &or ,ou:le value. The co,e has an
error.
1ection 3. Lperator ;rece,ence an, Associativit3.45 The or,er o& the prece,ence /&rom hi'h to lo+0 o& the operators :inar #* 2* FF* GG is
A. FF* GG* 2* #
B. 2* #* FF* GG
C. 2* #* GG* FF
D. GG* FF* 2* #
3.46 hat is ,isplae, in the &ollo+in' co,e%
pu:lic class Test
pu:lic static voi, main/1trin'OP ar's0
int 7 = 6 int = 7 = 7 # 6
1stem.out.println/" is " # 06
-
8/9/2019 Chapter 3 Selections.docx
16/16
A. is (.
B. is :ecause 7 is assi'ne, to &irst.
C. is ? :ecause 7 # is assi'ne, to 7 an, then 7 is assi'ne, to .
D. The pro'ram has a compile error since 7 is re,eclare, in the statement int = 7 = 7 # .
3.47 hich o& the &ollo+in' operators are ri'ht8associative.
A. 2
B. # /:inar #0
C.
D. FF
E. =
3.48 hat is the value o& the &ollo+in' e7pression%
true GG true FF &alseA. true
B. &alse
3.49 hich o& the &ollo+in' statements are true%
A. /7 > ( FF 7 < (0 is same as //7 > (0 FF /7 < (00
B. /7 > ( GG 7 < (0 is same as //7 > (0 GG /7 < (00
C. /7 > ( GG 7 < ( FF < (0 is same as /7 > ( GG /7 < ( FF < (00
D. /7 > ( GG 7 < ( FF < (0 is same as //7 > ( GG 7 < (0 FF < (0