SlideShare a Scribd company logo
1 of 10
Chapter 3 Selections
1. <, <=, ==, !=, >, >=
2.
true
false
false
true
true
true
3. No. Boolean values cannot be cast to other types.
4.
if (y > 0)
x = 1;
5.
if (score > 90)
pay *= 1.03;
6.
if (score > 90)
pay *= 1.03;
else
pay *= 1.01;
7.
If number is 30,
(a) displays
30 is even
30 is odd
(b) displays
30 is even
If number is 35,
(a) displays
35 is odd
(b) displays
35 is odd
8. Note: else matches the first if clause. No output if x = 3 and y = 2. Output is “z is
7” if if x = 3 and y = 4. Output is “x is 2” if if x = 2 and y = 2.
x > 2
falsetrue
System.out.println("x is " + x);
y > 2
false
true
int z = x + y;
System.out.println("z is " + z);
9. No output if x = 2 and y = 3. Output is “x is 3” if x = 3 and y = 2.
Output is “z is 6” if x = 3 and y = 3.
10.
Consider score is 90, what will be the grade?
11. a, c, and d are the same. (B) and (C) are correctly indented.
12.
newLine = (count % 10 == 0);
13.
Both are correct. (b) is better.
14. for (a) if number is 14, the output is
14 is even
if number is 15, the output is
15 is multiple of 5
if number is 30, the output is
30 is even
30 is multiple of 5
for (b) if number is 14, the output is
14 is even
if number is 15, the output is
15 is multiple of 5
if number is 30, the output is
30 is even
15. 0.5, 0.0, 0.234
16. (int)(Math.random() * 20)
10 + (int)(Math.random() * 10)
10 + (int)(Math.random() * 41)
17. Yes
18. (true) && (3 > 4)
false
!(x > 0) && (x > 0)
false
(x > 0) || (x < 0)
true
(x != 0) || (x == 0)
true
(x >= 0) || (x < 0)
true
(x != 1) == !(x == 1)
true
19. (x > 1) && (x < 100)
20. ((x > 1) && (x < 100)) || (x < 0)
21. x > y > 0
incorrect
x = y && y
incorrect
x /= y
correct
x or y
incorrect
x and y
incorrect
22.
a. x is 2.
b. x is 1.
23.
If ch is 'A', the expression is true;
If ch is 'p', the expression is false;
If ch is 'E', the expression is true;
If ch is '5', the expression is false;
24.
(x < y && y < z) is true
(x < y || y < z) is true
!(x < y) is false
(x + y < z) is true
(x + y < z) is true
25. age > 13 && age < 18
26.
weight > 50 || height > 60.
27.
weight > 50 && height > 60.
28.
weight > 50 ^ height > 60.
29. Switch variables must be of char, byte, short, or int data types. If a break
statement is not used, the next case statement is performed. You can always convert a
switch statement to an equivalent if statement, but not an if statement to a switch
statement. The use of the switch statement can improve readability of the program in some
cases. The compiled code for the switch statement is also more efficient than its
corresponding if statement.
30. y is 2.
31. x is 17
switch (a) {
case 1: x += 5; break;
case 2: x += 10; break;
case 3: x += 16; break;
case 4: x += 34;
}
a is 1
x += 5; break
x += 10; break
a is 2
x += 16; break
a is 3
x += 34; break
a is 4
32. switch (day) {
case 0: dayName = "Sunday"; break;
case 1: dayName = "Monday"; break;
case 2: dayName = "Tuesday"; break;
case 3: dayName = "Wednesday"; break;
case 4: dayName = "Thurday"; break;
case 5: dayName = "Friday"; break;
case 6: dayName = "Saturday"; break;
}
33. Sorted
34.
(A) ticketPrice = (ages >= 16) ? 20 : 10;
(B) System.out.print((count % 10 == 0) ? count + "n" : count + " ");
35.
(A)
if (x > 10)
score = 3 * scale;
else
score = 4 * scale;
(B)
if (income > 10000)
tax = income * 0.2;
else
tax = income * 0.17 + 1000;
(C)
if (number % 3 == 0)
System.out.println(i);
else
System.out.println(j);
36.
The specifiers for outputting a boolean value, a character, a
decimal integer, a floating-point number, and a string are
%b, %c, %d, %f, and %s.
37.
(a) the last item 3 does not have any specifier.
(b) There is not enough items
(c) The data for %f must a floating-point value
38.
(a) amount is 32.320000 3.233000e+01
(b) amount is 32.3200 3.2330e+01
(c) *false // * denote a space
(d) **Java // * denote a space
(e) false*****Java
(f) *falseJava
39. The precedence order for boolean operators is ^, &&, and ||
true || true && false is true
true && true || false is true
40. True
41. both are false
42. Yes. Yes. Yes.
43. To display a confirmation dialog box, invoke JOptionPane.showConfirmDialog(null, “Prompting
message”). The method returns an int value: 0 if the Yes button is clicked, 1 if the No button is
clicked, and 2 if the Cancel button is clicked,

More Related Content

What's hot

January 11
January 11January 11
January 11
khyps13
 
Rational Inequality Apr 20 09
Rational Inequality Apr 20 09Rational Inequality Apr 20 09
Rational Inequality Apr 20 09
ingroy
 
Nov. 17 Rational Inequalities
Nov. 17 Rational InequalitiesNov. 17 Rational Inequalities
Nov. 17 Rational Inequalities
RyanWatt
 
Nov. 16 Quadratic Inequalities
Nov. 16 Quadratic InequalitiesNov. 16 Quadratic Inequalities
Nov. 16 Quadratic Inequalities
RyanWatt
 
Algebra 7 Point 3
Algebra 7 Point 3Algebra 7 Point 3
Algebra 7 Point 3
herbison
 
Sulalgtrig7e Isg 1 2
Sulalgtrig7e Isg 1 2Sulalgtrig7e Isg 1 2
Sulalgtrig7e Isg 1 2
Joseph Eulo
 
Práctica 1 auxiliatura estadística
Práctica 1 auxiliatura estadísticaPráctica 1 auxiliatura estadística
Práctica 1 auxiliatura estadística
JoelAnara
 
11 – 28 journal
11 – 28 journal11 – 28 journal
11 – 28 journal
bweldon
 

What's hot (18)

January 11
January 11January 11
January 11
 
Rational Inequality Apr 20 09
Rational Inequality Apr 20 09Rational Inequality Apr 20 09
Rational Inequality Apr 20 09
 
Expresiones Algebraicas, Factorización y Radicación.
Expresiones Algebraicas, Factorización y Radicación.Expresiones Algebraicas, Factorización y Radicación.
Expresiones Algebraicas, Factorización y Radicación.
 
09 sistema de equação do primeiro grau
09 sistema de equação do primeiro grau09 sistema de equação do primeiro grau
09 sistema de equação do primeiro grau
 
Zero product property remediation notes
Zero product property remediation notesZero product property remediation notes
Zero product property remediation notes
 
Zero product property notes
Zero product property notesZero product property notes
Zero product property notes
 
Nov. 17 Rational Inequalities
Nov. 17 Rational InequalitiesNov. 17 Rational Inequalities
Nov. 17 Rational Inequalities
 
Nov. 16 Quadratic Inequalities
Nov. 16 Quadratic InequalitiesNov. 16 Quadratic Inequalities
Nov. 16 Quadratic Inequalities
 
Algebra 7 Point 3
Algebra 7 Point 3Algebra 7 Point 3
Algebra 7 Point 3
 
Ecuaciones de primer grado
Ecuaciones de primer gradoEcuaciones de primer grado
Ecuaciones de primer grado
 
wd9753xc
wd9753xcwd9753xc
wd9753xc
 
Nbv.edu.vn tong hop-cong-thuc-toan-thpt-nguyen-viet-hieu
Nbv.edu.vn tong hop-cong-thuc-toan-thpt-nguyen-viet-hieuNbv.edu.vn tong hop-cong-thuc-toan-thpt-nguyen-viet-hieu
Nbv.edu.vn tong hop-cong-thuc-toan-thpt-nguyen-viet-hieu
 
Sulalgtrig7e Isg 1 2
Sulalgtrig7e Isg 1 2Sulalgtrig7e Isg 1 2
Sulalgtrig7e Isg 1 2
 
Ecuaciones de primer grado
Ecuaciones de primer gradoEcuaciones de primer grado
Ecuaciones de primer grado
 
Next higher number with same number of binary bits set
Next higher number with same number of binary bits setNext higher number with same number of binary bits set
Next higher number with same number of binary bits set
 
Práctica 1 auxiliatura estadística
Práctica 1 auxiliatura estadísticaPráctica 1 auxiliatura estadística
Práctica 1 auxiliatura estadística
 
Sistema de ecuaciones
Sistema de ecuacionesSistema de ecuaciones
Sistema de ecuaciones
 
11 – 28 journal
11 – 28 journal11 – 28 journal
11 – 28 journal
 

Viewers also liked (9)

Bab i Contoh Penulisan KTI
Bab i Contoh Penulisan KTIBab i Contoh Penulisan KTI
Bab i Contoh Penulisan KTI
 
Webinar PRIMAVERA - Oportunidades Portugal 2020
Webinar PRIMAVERA - Oportunidades Portugal 2020Webinar PRIMAVERA - Oportunidades Portugal 2020
Webinar PRIMAVERA - Oportunidades Portugal 2020
 
Apostila para-operadores-de-empilhadeira-a-combustão.
Apostila para-operadores-de-empilhadeira-a-combustão.Apostila para-operadores-de-empilhadeira-a-combustão.
Apostila para-operadores-de-empilhadeira-a-combustão.
 
Lesson 1-self and socialization
Lesson 1-self and socializationLesson 1-self and socialization
Lesson 1-self and socialization
 
Lean Canvas
Lean CanvasLean Canvas
Lean Canvas
 
Political science nature and scope
Political science nature and scopePolitical science nature and scope
Political science nature and scope
 
Danny_Maribao_Lesson 8-political-organization
Danny_Maribao_Lesson 8-political-organizationDanny_Maribao_Lesson 8-political-organization
Danny_Maribao_Lesson 8-political-organization
 
Human evolution and culture
Human evolution and cultureHuman evolution and culture
Human evolution and culture
 
Seminario NFC: Presentación CIET Universidad Adolfo Ibáñez
Seminario NFC: Presentación CIET Universidad Adolfo IbáñezSeminario NFC: Presentación CIET Universidad Adolfo Ibáñez
Seminario NFC: Presentación CIET Universidad Adolfo Ibáñez
 

Similar to 03review

Lesson 5.3 honors
Lesson 5.3 honorsLesson 5.3 honors
Lesson 5.3 honors
morrobea
 
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdfPython-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdf
letsdism
 

Similar to 03review (20)

Review questions and answers
Review questions and answersReview questions and answers
Review questions and answers
 
Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)
 
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptxAIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
AIOU Code 1429 Solved Assignment 1 Autumn 2022.pptx
 
201707 CSE110 Lecture 13
201707 CSE110 Lecture 13   201707 CSE110 Lecture 13
201707 CSE110 Lecture 13
 
Lr4 math cad
Lr4 math cadLr4 math cad
Lr4 math cad
 
Logic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean AlgebraLogic Design - Chapter 3: Boolean Algebra
Logic Design - Chapter 3: Boolean Algebra
 
conditional.ppt
conditional.pptconditional.ppt
conditional.ppt
 
tetris
tetristetris
tetris
 
Python
PythonPython
Python
 
“Introduction to MATLAB & SIMULINK”
“Introduction to MATLAB  & SIMULINK”“Introduction to MATLAB  & SIMULINK”
“Introduction to MATLAB & SIMULINK”
 
Factoring polynomials
Factoring polynomialsFactoring polynomials
Factoring polynomials
 
Tech-1.pptx
Tech-1.pptxTech-1.pptx
Tech-1.pptx
 
Quadratic equations that factorise
Quadratic equations that factoriseQuadratic equations that factorise
Quadratic equations that factorise
 
Lesson 5.3 honors
Lesson 5.3 honorsLesson 5.3 honors
Lesson 5.3 honors
 
Appt and reasoning
Appt and reasoningAppt and reasoning
Appt and reasoning
 
Lesson-6-Trigonometric-Identities.pptx
Lesson-6-Trigonometric-Identities.pptxLesson-6-Trigonometric-Identities.pptx
Lesson-6-Trigonometric-Identities.pptx
 
101 math short cuts [www.onlinebcs.com]
101 math short cuts [www.onlinebcs.com]101 math short cuts [www.onlinebcs.com]
101 math short cuts [www.onlinebcs.com]
 
Ch4
Ch4Ch4
Ch4
 
Python-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdfPython-3-compiled-Cheat-Sheet-version-3.pdf
Python-3-compiled-Cheat-Sheet-version-3.pdf
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 

Recently uploaded

College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
perfect solution
 

Recently uploaded (20)

College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
 
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore EscortsVIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escorts
 
Call Girls Ludhiana Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 9907093804 Top Class Call Girl Service Available
 
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any TimeTop Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
 
Top Rated Bangalore Call Girls Mg Road ⟟ 9332606886 ⟟ Call Me For Genuine S...
Top Rated Bangalore Call Girls Mg Road ⟟   9332606886 ⟟ Call Me For Genuine S...Top Rated Bangalore Call Girls Mg Road ⟟   9332606886 ⟟ Call Me For Genuine S...
Top Rated Bangalore Call Girls Mg Road ⟟ 9332606886 ⟟ Call Me For Genuine S...
 
The Most Attractive Hyderabad Call Girls Kothapet 𖠋 6297143586 𖠋 Will You Mis...
The Most Attractive Hyderabad Call Girls Kothapet 𖠋 6297143586 𖠋 Will You Mis...The Most Attractive Hyderabad Call Girls Kothapet 𖠋 6297143586 𖠋 Will You Mis...
The Most Attractive Hyderabad Call Girls Kothapet 𖠋 6297143586 𖠋 Will You Mis...
 
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
 
Call Girls Jabalpur Just Call 8250077686 Top Class Call Girl Service Available
Call Girls Jabalpur Just Call 8250077686 Top Class Call Girl Service AvailableCall Girls Jabalpur Just Call 8250077686 Top Class Call Girl Service Available
Call Girls Jabalpur Just Call 8250077686 Top Class Call Girl Service Available
 
Best Rate (Patna ) Call Girls Patna ⟟ 8617370543 ⟟ High Class Call Girl In 5 ...
Best Rate (Patna ) Call Girls Patna ⟟ 8617370543 ⟟ High Class Call Girl In 5 ...Best Rate (Patna ) Call Girls Patna ⟟ 8617370543 ⟟ High Class Call Girl In 5 ...
Best Rate (Patna ) Call Girls Patna ⟟ 8617370543 ⟟ High Class Call Girl In 5 ...
 
Call Girls Coimbatore Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Coimbatore Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Coimbatore Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Coimbatore Just Call 9907093804 Top Class Call Girl Service Available
 
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
 
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore EscortsCall Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
 
VIP Service Call Girls Sindhi Colony 📳 7877925207 For 18+ VIP Call Girl At Th...
VIP Service Call Girls Sindhi Colony 📳 7877925207 For 18+ VIP Call Girl At Th...VIP Service Call Girls Sindhi Colony 📳 7877925207 For 18+ VIP Call Girl At Th...
VIP Service Call Girls Sindhi Colony 📳 7877925207 For 18+ VIP Call Girl At Th...
 
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
 
Night 7k to 12k Chennai City Center Call Girls 👉👉 7427069034⭐⭐ 100% Genuine E...
Night 7k to 12k Chennai City Center Call Girls 👉👉 7427069034⭐⭐ 100% Genuine E...Night 7k to 12k Chennai City Center Call Girls 👉👉 7427069034⭐⭐ 100% Genuine E...
Night 7k to 12k Chennai City Center Call Girls 👉👉 7427069034⭐⭐ 100% Genuine E...
 
Premium Bangalore Call Girls Jigani Dail 6378878445 Escort Service For Hot Ma...
Premium Bangalore Call Girls Jigani Dail 6378878445 Escort Service For Hot Ma...Premium Bangalore Call Girls Jigani Dail 6378878445 Escort Service For Hot Ma...
Premium Bangalore Call Girls Jigani Dail 6378878445 Escort Service For Hot Ma...
 
VIP Hyderabad Call Girls Bahadurpally 7877925207 ₹5000 To 25K With AC Room 💚😋
VIP Hyderabad Call Girls Bahadurpally 7877925207 ₹5000 To 25K With AC Room 💚😋VIP Hyderabad Call Girls Bahadurpally 7877925207 ₹5000 To 25K With AC Room 💚😋
VIP Hyderabad Call Girls Bahadurpally 7877925207 ₹5000 To 25K With AC Room 💚😋
 
Call Girls Tirupati Just Call 8250077686 Top Class Call Girl Service Available
Call Girls Tirupati Just Call 8250077686 Top Class Call Girl Service AvailableCall Girls Tirupati Just Call 8250077686 Top Class Call Girl Service Available
Call Girls Tirupati Just Call 8250077686 Top Class Call Girl Service Available
 
Book Paid Powai Call Girls Mumbai 𖠋 9930245274 𖠋Low Budget Full Independent H...
Book Paid Powai Call Girls Mumbai 𖠋 9930245274 𖠋Low Budget Full Independent H...Book Paid Powai Call Girls Mumbai 𖠋 9930245274 𖠋Low Budget Full Independent H...
Book Paid Powai Call Girls Mumbai 𖠋 9930245274 𖠋Low Budget Full Independent H...
 

03review

  • 1. Chapter 3 Selections 1. <, <=, ==, !=, >, >= 2. true false false true true true 3. No. Boolean values cannot be cast to other types. 4. if (y > 0) x = 1; 5. if (score > 90) pay *= 1.03; 6. if (score > 90) pay *= 1.03; else pay *= 1.01;
  • 2. 7. If number is 30, (a) displays 30 is even 30 is odd (b) displays 30 is even If number is 35, (a) displays 35 is odd (b) displays 35 is odd 8. Note: else matches the first if clause. No output if x = 3 and y = 2. Output is “z is 7” if if x = 3 and y = 4. Output is “x is 2” if if x = 2 and y = 2.
  • 3. x > 2 falsetrue System.out.println("x is " + x); y > 2 false true int z = x + y; System.out.println("z is " + z); 9. No output if x = 2 and y = 3. Output is “x is 3” if x = 3 and y = 2. Output is “z is 6” if x = 3 and y = 3. 10. Consider score is 90, what will be the grade? 11. a, c, and d are the same. (B) and (C) are correctly indented. 12. newLine = (count % 10 == 0); 13. Both are correct. (b) is better. 14. for (a) if number is 14, the output is
  • 4. 14 is even if number is 15, the output is 15 is multiple of 5 if number is 30, the output is 30 is even 30 is multiple of 5 for (b) if number is 14, the output is 14 is even if number is 15, the output is 15 is multiple of 5 if number is 30, the output is 30 is even 15. 0.5, 0.0, 0.234 16. (int)(Math.random() * 20) 10 + (int)(Math.random() * 10) 10 + (int)(Math.random() * 41) 17. Yes 18. (true) && (3 > 4) false
  • 5. !(x > 0) && (x > 0) false (x > 0) || (x < 0) true (x != 0) || (x == 0) true (x >= 0) || (x < 0) true (x != 1) == !(x == 1) true 19. (x > 1) && (x < 100) 20. ((x > 1) && (x < 100)) || (x < 0) 21. x > y > 0 incorrect x = y && y incorrect
  • 6. x /= y correct x or y incorrect x and y incorrect 22. a. x is 2. b. x is 1. 23. If ch is 'A', the expression is true; If ch is 'p', the expression is false; If ch is 'E', the expression is true; If ch is '5', the expression is false; 24. (x < y && y < z) is true (x < y || y < z) is true !(x < y) is false (x + y < z) is true (x + y < z) is true
  • 7. 25. age > 13 && age < 18 26. weight > 50 || height > 60. 27. weight > 50 && height > 60. 28. weight > 50 ^ height > 60. 29. Switch variables must be of char, byte, short, or int data types. If a break statement is not used, the next case statement is performed. You can always convert a switch statement to an equivalent if statement, but not an if statement to a switch statement. The use of the switch statement can improve readability of the program in some cases. The compiled code for the switch statement is also more efficient than its corresponding if statement. 30. y is 2. 31. x is 17 switch (a) { case 1: x += 5; break; case 2: x += 10; break; case 3: x += 16; break;
  • 8. case 4: x += 34; } a is 1 x += 5; break x += 10; break a is 2 x += 16; break a is 3 x += 34; break a is 4 32. switch (day) { case 0: dayName = "Sunday"; break; case 1: dayName = "Monday"; break; case 2: dayName = "Tuesday"; break; case 3: dayName = "Wednesday"; break; case 4: dayName = "Thurday"; break; case 5: dayName = "Friday"; break; case 6: dayName = "Saturday"; break; } 33. Sorted 34. (A) ticketPrice = (ages >= 16) ? 20 : 10;
  • 9. (B) System.out.print((count % 10 == 0) ? count + "n" : count + " "); 35. (A) if (x > 10) score = 3 * scale; else score = 4 * scale; (B) if (income > 10000) tax = income * 0.2; else tax = income * 0.17 + 1000; (C) if (number % 3 == 0) System.out.println(i); else System.out.println(j); 36. The specifiers for outputting a boolean value, a character, a decimal integer, a floating-point number, and a string are %b, %c, %d, %f, and %s. 37. (a) the last item 3 does not have any specifier. (b) There is not enough items (c) The data for %f must a floating-point value 38. (a) amount is 32.320000 3.233000e+01 (b) amount is 32.3200 3.2330e+01 (c) *false // * denote a space
  • 10. (d) **Java // * denote a space (e) false*****Java (f) *falseJava 39. The precedence order for boolean operators is ^, &&, and || true || true && false is true true && true || false is true 40. True 41. both are false 42. Yes. Yes. Yes. 43. To display a confirmation dialog box, invoke JOptionPane.showConfirmDialog(null, “Prompting message”). The method returns an int value: 0 if the Yes button is clicked, 1 if the No button is clicked, and 2 if the Cancel button is clicked,