You are on page 1of 25

Solutions Chapter 5: Decisions Multiple Choice

1. What kind of statement lets a program carry out different actions depending on a condition? A) if B) decision C) which D) condition Ans: A Section Ref: Section 5.1 The if Statement Title: TB 5.1 What kind of statement lets a program carry out different actions depending on a condition? Difficulty: Easy

2. What kind of statement groups several statements together? A) simple B) boolean C) block D) condition Ans: C Section Ref: Section 5.1 The if Statement Title: TB 5.2 What kind of statement groups several statements together? Difficulty: Easy

3. Block statements are enclosed by _____________? A) < > B) { } C) [ ] D) ( ) Ans: B Section Ref: Section 5.1 The if Statement Title: TB 5.3 Block statements are enclosed by _____________? Difficulty: Easy

4. Conditions are enclosed by _____________? A) ( ) B) < >

C) [ ] D) { } Ans: A Section Ref: Section 5.1 The if Statement Title: TB 5.4 Conditions are enclosed by _____________? Difficulty: Easy

5. Which if condition correctly checks whether there are sufficient funds in the bank account? A) if (balance = amount) B) if {balance >= amount} C) if [balance >= amount] D) if (balance >= amount) Ans: D Section Ref: Section 5.1 The if Statement Title: TB 5.5 Which if condition correctly checks whether there are sufficient funds in the bank account? Difficulty: Easy

6. The following code is an example of what kind of statement? balance = balance - amount; A) simple B) block C) loop D) compound Ans: A Section Ref: Section 5.1 The if Statement Title: TB 5.6 The following code is an example of what kind of statement? Difficulty: Medium

7. The following code is an example of what kind of statement? if (balance >= amount) balance = balance - amount; A) loop B) compound C) simple D) block Ans: B Section Ref: Section 5.1 The if Statement Title: TB 5.7 The following code is an example of what kind of statement?

Difficulty: Medium

8. Which Java statement correctly implements the following pseudocode: Display "A" when the student's grade is higher than 90 (inclusive) A) if (studentGrade = 90) System.out.println("A"); B) if (studentGrade > 90) System.out.println("A"); C) if (studentGrade >= 90) System.out.println("A"); D) if (studentGrade < 90) System.out.println("A"); Ans: C Section Ref: Section 5.1 The if Statement Title: TB 5.8 Which Java statement correctly implements the following pseudocode for a grade higher than 90 (inclusive): Difficulty: Medium

9. Which statement is true about the following code fragment involving a conditional? if (amount > balance) ; System.out.println("Insufficient funds"); A) Never prints out "Insufficient funds". B) Does not compile. C) Only prints out "Insufficient funds" when amount > balance D) Always prints out "Insufficient funds". Ans: D Section Ref: Section 5.1 The if Statement Title: TB 5.9 Which statement is true about the following code fragment involving a conditional? Difficulty: Medium

10. What is the following operator called where the value of the expression is either value1 if the condition is true or value2 if it is false? condition ? value1 : value2; A) conditional B) switch C) question mark D) if/else

Ans: A Section Ref: Special Topic 5.1 The Selection Operator Title: TB 5.10 What is the following operator called where the value of the expression is either value1 if the condition is true or value2 if it is false? Difficulty: Easy

11. Consider the code fragment involving a selection operator: q = (p % 4) != 0 ? (p % 4) : 4; What is the value of q when p is 8? A) 3 B) 2 C) 0 D) 4 Ans: D Section Ref: Special Topic 5.1 The Selection Operator Title: TB 5.11 What is the value of the selection? Difficulty: Easy

12. Consider the code fragment involving a selection operator: q = (p % 4) != 0 ? (p % 4) : 4; What is the value of q when p is 9? A) 0 B) 4 C) 2 D) 1 Ans: D Section Ref: Special Topic 5.1 The Selection Operator Title: TB 5.12 What is the value of the selection? Difficulty: Easy

13. The following statement involving the selection operator is similar to which statement? y = x >= 0 ? x : -x; A) if (x y = else y = B) if (x >= 0) x; -x; >= 0)

y = C) if (x y = D) if (x y = else y =

x; >= 0) -x; >= 0) -x; x;

Ans: A Section Ref: Special Topic 5.1 The Selection Operator Title: TB 5.13 Which statement is similar to the statement given involving the selection operator? Difficulty: Hard

14. What kind of operator compares two values? A) conditional B) boolean C) relational D) predicate Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.14 What kind of operator compares two values? Difficulty: Easy

15. Which operator tests for equality? A) != B) === C) = D) == Ans: D Section Ref: Section 5.2 Comparing Values Title: TB 5.15 Which operator tests for equality? Difficulty: Easy

16. Which of the following is a relational operator? A) != B) || C) / D) && Ans: A Section Ref: Section 5.2 Comparing Values Title: TB 5.16 Which of the following is a relational operator?

Difficulty: Medium

17. What is the opposite of the operator < ? A) > B) >= C) <= D) => Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.17 What is the opposite of the operator < ? Difficulty: Easy

18. What is the opposite of the operator > ? A) =< B) <= C) < D) => Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.18 What is the opposite of the operator > ? Difficulty: Easy

19. Which operator should you use to test whether an object reference is null? A) == B) >= C) <= D) = Ans: A Section Ref: Section 5.2 Comparing Values Title: TB 5.19 Which operator should you use to test whether an object reference is null? Difficulty: Medium

20. Which is the preferred approach to determine whether two integer variables (i1 and i2) are equal, assuming the following declarations? int i1; int i2; final double EPSILON = 1E-14; A) if (i1 == i2) ...

B) if Math.abs(i1 - i2) <= EPSILON ... C) if (Math.abs(i1 - i2) <= EPSILON) ... D) if (i1 = i2) ... Ans: A Section Ref: Section 5.2 Comparing Values Title: TB 5.20 Which is the preferred approach to determine whether two integer variables (i1 and i2) are equal? Difficulty: Easy

21. Which is the preferred approach to determine whether two double variables (d1 and d2) are equal, assuming the following declarations? double d1; double d2; final double EPSILON = 1E-14; A) if B) if C) if D) if (d1 = d2) ... Math.abs(d1 - d2) <= EPSILON ... (Math.abs(d1 - d2) <= EPSILON) ... (d1 == d2) ...

Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.21 Which is the preferred approach to determine whether two double variables (d1 and d2) are equal? Difficulty: Medium

22. Which condition should be used to test whether the contents of two strings referenced by string1 and string2 have the same value? A) (string1.equals(string2)) B) (String.equals(string1, string2)) C) (string1 == string2) D) (Equals(string1, string2)) Ans: A Section Ref: Section 5.2 Comparing Values Title: TB 5.22 Which condition should be used to test whether the contents of two strings referenced by string1 and string2 have the same value? Difficulty: Easy

23. Which method compares strings in dictionary order? A) compare B) compareDictionary

C) equals D) compareTo Ans: D Section Ref: Section 5.2 Comparing Values Title: TB 5.23 Which method compares strings in dictionary order? Difficulty: Easy

24. What does it mean if the following test is true: s.compareTo(t) < 0? A) s is null B) t is null C) s comes before t in the dictionary D) s comes after t in the dictionary Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.24 What does it mean if the following test is true: s.compareTo(t) < 0 ? Difficulty: Medium

25. What does it mean if string1 comes after string2 in dictionary order? A) string2.compareTo(string1) > 0 B) string1.compareTo(string2) < 0 C) string1.compareTo(string2) > 0 D) string2.compareTo(string1) <> 0 Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.25 What does it mean if string1 comes after string in dictionary order? Difficulty: Medium

26. If string1 and string2 are equal, then string1.compareTo(string2) _______. A) .equals(0) B) == 0 C) == true D) == null Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.26 If string1 and string2 are equal, then string1.compareTo(string2) ______. Difficulty: Medium

27. Which choice indicates that a string variable refers to no string?

A) nil B) "" C) null D) empty Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.27 Which choice indicates that a string variable refers to no string? Difficulty: Medium

28. Which choice denotes an empty string? A) empty B) "" C) nil D) null Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.28 Which choice denotes an empty string? Difficulty: Medium

29. Consider the following code: String greeting = "Hello, World!"; String hello1 = "Hello"; String hello2 = greeting.substring(0,6); String hello3 = hello1; Which statement correctly checks whether hello1 and hello2 have the same value and displays the string "Hello"? A) if hello2 == hello1 System.out.println("Hello"); B) if (hello1.equals(hello2)) System.out.println("Hello"); C) if (hello1 == hello2) System.out.println("Hello"); D) if hello2.equals(hello1) System.out.println("Hello"); Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.29 Which statement correctly checks whether hello1 and hello2 have the same value and displays the string "Hello"? Difficulty: Medium

30. Consider the following code: String greeting = "Hello, World!"; String hello1 = "Hello"; String hello2 = greeting.substring(0,6); String hello3 = hello1; Which statement correctly checks whether hello1 and hello3 are identical string references and displays the string "Hello"? A) if hello3.equals(hello1) System.out.println("Hello"); B) if (hello1.equals(hello3)) System.out.println("Hello"); C) if (hello1 == hello3) System.out.println("Hello"); D) if hello3 == hello1 System.out.println("Hello"); Ans: C Section Ref: Section 5.2 Comparing Values Title: TB 5.30 Which statement correctly checks whether hello1 and hello3 are identical string references and displays the string "Hello"? Difficulty: Medium

31. Which operator or method tests whether two object references are identical? A) == B) equals C) = D) identity Ans: A Section Ref: Section 5.2 Comparing Values Title: TB 5.31 Which operator or method tests whether two object references are identical? Difficulty: Easy

32. Which operator or method should you use to determine whether the contents of objects have the same value? A) == B) equals C) = D) same Ans: B Section Ref: Section 5.2 Comparing Values

Title: TB 5.32 Which operator or method should you use to determine whether the contents of objects have the same value? Difficulty: Easy

33. Consider the following code: Faculty f = new Faculty(...); Student s = new Student(...); // Assume f is assigned as the advisor of the student Faculty deptChair = f; Which statement correctly checks whether the faculty advisor of a student is in the department in which a student is majoring, assuming that getMajor, getAdvisor, and getDept are valid accessor methods? A) if B) if C) if D) if s.getAdvisor.getDept.equals(s.getMajor) {...} ; s.getAdvisor().getDept().equals(s.getMajor()) {...} ; (s.getMajor.equals(s.getAdvisor.getDept)) {...} ; (s.getMajor().equals(s.getAdvisor().getDept())) {...} ;

Ans: D Section Ref: Section 5.2 Comparing Values Title: TB 5.33 Which statement correctly checks whether the faculty advisor of a student is in the department in which a student is majoring? Difficulty: Medium

34. Consider the following code: Student s = new Student(...); Which statement correctly checks whether the student has been assigned a faculty advisor, assuming that getAdvisor is a valid accessor method? A) if B) if C) if D) if (s.getAdvisor() = null) {...} ; (s.getAdvisor() == null) {...} ; s.getAdvisor() = null {...} ; (s.getAdvisor == null) {...} ;

Ans: B Section Ref: Section 5.2 Comparing Values Title: TB 5.34 Which statement correctly checks whether the student has been assigned a faculty advisor? Difficulty: Medium

35. Which is the correct Java code to assign a letter grade (A, B, or C) to a student based on a score? A) if (score >= 90) letterGrade="A";

else if (score >= 80) letterGrade = "B"; else letterGrade = "C"; B) if (score >= 90) letterGrade="A" else if (score >= 80) letterGrade = "B" else letterGrade = "C"; C) if (score >= 70) letterGrade="C"; else if (score >= 80) letterGrade = "B"; letterGrade = "A"; D) if (score >= 90) letterGrade="A"; if (score >= 80) letterGrade = "B"; if (score >= 70) letterGrade = "C"; Ans: A Section Ref: Section 5.3 Multiple Alternatives Title: TB 5.35 Which is the correct Java code to assign a letter grade to a student based on a score? Difficulty: Medium

36. What type of statement can be used to implement a sequence of if/else/else that compares a single value against several constant alternatives? A) compare B) ifElse C) switch D) sequence Ans: C Section Ref: Special Topic 5.2 The switch Statement Title: TB 5.36 What type of statement can be used to implement a sequence of if/else/else that compares a single value against several constant alternatives? Difficulty: Easy

37. Which code fragment involving a switch correctly maps a letter grade to a gpa value, assuming the following declarations? String letterGrade; double gpaValue;

A) Char letter = letterGrade.charAt(0); switch (letter) { 'A': gpaValue = 4.0; break; ... } B) switch (letterGrade) { "A": gpaValue = 4.0; ... } C) switch (letterGrade) { "A": gpaValue = 4.0; break; ... } D) switch (letterGrade) { A: gpaValue = 4.0; break; ... } Ans: A Section Ref: Special Topic 5.2 The switch Statement Title: TB 5.37 Which code fragment involving a switch correctly maps a letter grade to a gpa value? Difficulty: Medium

38. Consider the following code fragment: String letterGrade = ""; if (grade < 90) if (grade >= 80) letterGrade = "B"; else letterGrade = "A"; System.out.println(letterGrade); What is the value of letterGrade when the grade is 95? A) null B) "A" C) "B" D) "" Ans: D Section Ref: Section 5.3 Multiple Alternatives Title: TB 5.38 What is the value of letterGrade when the grade is 95? Difficulty: Medium

39. What type has a finite set of values? A) String B) double C) int D) enumerated Ans: D Section Ref: Special Topic 5.3 Enumerated Types Title: TB 5.39 What type has a finite set of values? Difficulty: Medium

40. An enumerated type variable can have ___ A) an infinite number of values or null B) a finite number of predetermined values but not null C) a finite number of predeternimed values, or null D) an infinite number of values Ans: C Section Ref: Special Topic 5.3 Enumerated Types Title: TB 5.40 An enumerated type variable can have ___ Difficulty: Medium

41. Which statement correctly declares an enumerated type for the classification of students? A) public enum StudentClassification { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } B) public enumerated StudentClassification { "FRESHMAN", "SOPHOMORE", "JUNIOR", "SENIOR"} C) public enum StudentClassification = { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } D) public enumerated StudentClassification = { FRESHMAN, SOPHOMORE, JUNIOR, SENIOR } Ans: A Section Ref: Special Topic 5.3 Enumerated Types Title: TB 5.41 Which statement correctly declares an enumerated type for the classification of students? Difficulty: Medium

42. Which statement correctly checks the value of an enumerated type variable, assuming the following declarations? public enum Semester { SPRING, SUMMER, FALL, WINTER } Semester currentSemester; // Assume assigned a valid value

A) if B) if C) if D) if

(currentSemester == FALL) {...}; (currentSemester == Semester.FALL) {...}; (currentSemester.equals(Semester.FALL)) {...}; currentSemester.equals(Semester.FALL) {...};

Ans: B Section Ref: Special Topic 5.3 Enumerated Types Title: TB 5.42 Which statement correctly checks the value of an enumerated type variable? Difficulty: Medium

43. Which type has the two values: true and false? A) enumerated B) predicate C) flag D) boolean Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.43 Which type has the two values: true and false? Difficulty: Easy

44. Which operator takes a single condition and evaluates to true if that condition is false and false if that condition is true? A) ~ B) ! C) != D) not Ans: B Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.44 Which operator takes a single condition and evaluates to true if that condition is false and false if that condition is true? Difficulty: Easy

45. What type of method returns a boolean value? A) void B) static C) final D) predicate Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.45 What type of method returns a boolean value? Difficulty: Easy

46. The following code fragment is an example of a ___ method. public boolean hasAvailableFunds() { return balance > 0; } A) predicate B) conditional C) static D) relational Ans: A Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.46 This is an example of a ___ method. Difficulty: Medium

47. The operators &&, ||, and ! are what type of operators? A) conditional B) conjunction C) relational D) boolean Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.47 The operators &&, ||, and ! are what type of operators? Difficulty: Easy

48. What is the name of the && operator? A) and B) not C) ampersand D) or Ans: A Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.48 What is the name of the && operator? Difficulty: Easy

49. What is the name of the || operator? A) not B) and C) vertical bar

D) or Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.49 What is the name of the || operator? Difficulty: Easy

50. What is the name of the ! operator? A) not B) exclamation mark C) or D) and Ans: A Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.50 What is the name of the ! operator? Difficulty: Easy

51. Which operator combines several tests into a new test that passes only when all conditions are true? A) == B) || C) ! D) && Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.51 Which operator combines several tests into a new test that passes only when all conditions are true? Difficulty: Easy

52. Which operator combines several tests into a new test that succeeds if at least one of the conditions is true? A) || B) == C) ! D) && Ans: A Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.52 Which operator combines several tests into a new test that succeeds if at least one of the conditions is true? Difficulty: Easy

53. What is the value of the following boolean expression when x is 100? 0 < x && x < 100 A) false B) true C) The code has a syntax error and will not compile. D) The code compiles but has a logic error. Ans: A Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.53 What is the value of the boolean expression involving and? Difficulty: Medium

54. What is the value of the following boolean expression when s is "y"? s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("N") A) The code has a syntax error and will not compile. B) true C) false D) The code compiles but has a logic error. Ans: B Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.54 What is the value of the boolean expression involving or? Difficulty: Medium

55. What is the value of the following boolean expression when x is -10? 0 < x || x < 100 A) true B) The code compiles but has a logic error. C) The code has a syntax error and will not compile. D) false Ans: B Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.55 What is the value of the boolean expression involving or? Difficulty: Medium

56. What is the value of the following boolean expression when x is 100? !(0 < x)

A) The code compiles but has a logic error. B) true C) The code has a syntax error and will not compile. D) false Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.56 What is the value of the boolean expression involving not? Difficulty: Medium

57. Consider the following code fragment: Circle c1 = new Circle(3); Circle c2 = new Circle(3); Circle c3 = c2; boolean condition = c1 == c2; What is the value of condition? A) true B) The code has a syntax error and will not compile. C) false D) The code compiles but has a logic error. Ans: C Section Ref: Section 5.2 Comparing Values, Section 5.4 Using Boolean Expressions Title: TB 5.57 What is the value of the boolean condition that compares objects? Difficulty: Medium

58. Consider the following code fragment: Circle c1 = new Circle(3); Circle c2 = new Circle(3); Circle c3 = c2; boolean condition = c3.equals(c1); What is the value of condition assuming that two circles are considered equal if they have the same radius value? A) false B) true C) The code compiles but has a logic error. D) The code has a syntax error and will not compile. Ans: B Section Ref: Section 5.2 Comparing Values, Section 5.4 Using Boolean Expressions Title: TB 5.58 What is the value of the boolean condition that compares objects? Difficulty: Medium

59. Consider the following code fragment: int i1 = 7; int i2 = (2 * 4) - 1; int i3 = 11 - 2 * 2; boolean condition = i1 == i2; What is the value of condition? A) true B) The code compiles but has a logic error. C) false D) The code has a syntax error and will not compile. Ans: A Section Ref: Section 5.2 Comparing Values, Section 5.4 Using Boolean Expressions Title: TB 5.59 What is the value of the boolean condition that compares values? Difficulty: Medium

60. Which of the following conditions tests whether x is between 1 and 10 (inclusive)? A) 1 <= x && x < 10 B) 1 < x && x <= 10 C) 10 >= x && x >= 1 D) 1 <= x <= 10 Ans: C Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.60 Which of the following conditions tests whether x is between 1 and 10 (inclusive)? Difficulty: Medium

61. Consider the following code fragment: String s1 = "Y"; String s2 = "y" boolean condition = s2.equalsIgnoreCase(s1); What is the value of condition? A) The code compiles but has a logic error. B) The code has a syntax error and will not compile. C) false D) true Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.61 What is the value of the boolean condition that compares strings? Difficulty: Medium

62. Consider the following code fragment: response == 'Y' || value <= 6 && value >= 1; Which of the following conditions is equivalent to the code fragment? A) (response == 'Y' || (1 <= value <= 6)); B) ((response == 'Y' || value <= 6) && value >= 1); C) (response == 'Y' || (value <= 6 && value >= 1)); D) ((response == 'Y' || value >= 1) && value <= 6); Ans: C Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.62 Which of the following conditions is equivalent to the code fragment involving boolean expressions? Difficulty: Medium

63. Which of the following statements determines whether the input string is a question? A) input.charAt(input.length()) == '?' B) input.charAt(input.length()-1).equals("?") C) input.charAt(input.length()-1) == "?" D) input.charAt(input.length()-1) == '?' Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.63 Which of the following statements determines whether the input string is a question? Difficulty: Medium

64. In XML, an element has an opening tag and a matching closing tag. Tag names are enclosed by an opening angle bracket (<) and a closing angle bracket (>). Which of the following statements determines whether the input string is enclosed in angle brackets? A) input.charAt(0).equals("<") && input.charAt(input.length()1).equals(">") B) input.charAt(0) == "<" && input.charAt(input.length()-1) == ">" C) input.charAt(0) == '<' && input.charAt(input.length()) == '>' D) input.charAt(0) == '<' && input.charAt(input.length()-1) == '>' Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.64 Which of the following statements determines whether the input string is enclosed in angle brackets? Difficulty: Medium

65. What is the definition of lazy evaluation in the context of boolean operators?

A) Logical expressions are evaluated from left to right, and evaluation stops as soon as the truth value is determined. B) Logical expressions are combined into a new test that succeeds if at least one of the conditions is true. C) Logical expressions are combined into a new test that evaluates to true if that condition is false and false if that condition is true. D) Logical expressions are combined into a new test that passes only when all conditions are true. Ans: A Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.65 What is the definition of lazy evaluation in the context of boolean operators? Difficulty: Easy

66. Which of the following operators uses lazy evaluation? A) & B) | C) ! D) && Ans: D Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.66 Which of the following operators uses lazy evaluation? Difficulty: Medium

67. Consider the following code fragment: String input = JOptionPane.showInputDialog("Enter item quantity: "); Which statement illustrates a correct application of lazy evaluation? A) validInput = input != null & Integer.parseInt(input) > 0; B) validInput = Integer.parseInt(input) > 0 & input != null; C) validInput = Integer.parseInt(input) > 0 && input != null ; D) validInput = input != null && Integer.parseInt(input) > 0; Ans: D Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.67 Which statement illustrates a correct application of lazy evaluation? Difficulty: Medium

68. Consider the following code fragment: validInput = input != null && Integer.parseInt(input) > 0; Under which condition will lazy evaluation occur? A) Integer.parseInt(input) <= 0 B) input != null C) Integer.parseInt(input) > 0

D) input == null Ans: D Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.68 Which statement illustrates a correct application of lazy evaluation? Difficulty: Medium

69. Consider the following code fragment: String input = JOptionPane.showInputDialog("Continue (Y or N)? "); if (input != null) ___________________________________; Which statement illustrates a correct application of lazy evaluation? A) validInput = input.equals("Y") || input.equals("N"); B) validInput = input.equals('Y') || input.equals('N'); C) validInput = input.equals("Y" || "N"); D) validInput = input.equals('Y' || 'N'); Ans: A Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.69 Which statement completes the code fragment, illustrating a correct application of lazy evaluation? Difficulty: Medium

70. Consider the following code fragment: validInput = input.equals("Y") || input.equals("N"); Under which condition will lazy evaluation occur? A) !input.equals("N") B) input.equals("Y") C) input.equals("N") D) !input.equals("Y") Ans: B Section Ref: Special Topic 5.4: Lazy Evaluation of Boolean Operators Title: TB 5.70 Which statement illustrates a correct application of lazy evaluation? Difficulty: Medium

71. Consider the following code fragment: String input = in.next(); Which of the following conditions tests whether the user input is NOT Yes (ignoring case)? A) if !(input.equalsIgnoreCase("Yes")) {...}

B) if !(input.equalsIgnoreCase('Yes')) {...} C) if (!input.equalsIgnoreCase('Yes')) {...} D) if (!input.equalsIgnoreCase("Yes")) {...} Ans: D Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.71 Which of the following conditions tests whether the user input is NOT Yes (ignoring case)? Difficulty: Hard

72. You can store the outcome of a condition in what type of variable? A) predicate B) logical C) boolean D) conditional Ans: C Section Ref: Section 5.4 Using Boolean Expressions Title: TB 5.72 You can store the outcome of a condition in what type of variable? Difficulty: Easy

73. Which of the following conditions tests whether x is NOT between 1 and 10 (inclusive)? A) 10 < x || x < 1 B) !(1 <= x <= 10) C) 1 <= x || x <= 10 D) 1 > x && x <= 10 Ans: A Section Ref: Special Topic 5.5 DeMorgans Laws Title: TB 5.73 Which of the following conditions tests whether x is NOT between 1 and 10 (inclusive)? Difficulty: Hard

74. In XML, an element has an opening tag and a matching closing tag. Tag names are enclosed by an opening angle bracket (<) and a closing angle bracket (>). Which of the following statements determines whether the input string is NOT enclosed in angle brackets? A) input.charAt(0) != '<' || input.charAt(input.length()-1) != '>' B) input.charAt(0) != '<' && input.charAt(input.length()) != '>' C) input.charAt(0) == '<' && input.charAt(input.length()-1) == '>' D) input.charAt(0) != "<" || input.charAt(input.length()-1) != ">" Ans: A Section Ref: Special Topic 5.5 DeMorgans Laws

Title: TB 5.74 Which of the following statements determines whether the input string is NOT enclosed in angle brackets? Difficulty: Hard

75. Which of the following statements determines whether a person is ineligible for a junior or senior discount, assuming that a person is eligible for the discount if they are younger than 18 or older than 62? A) age >= 18 && age > 62 B) age >= 18 || age <= 62 C) age <= 18 || age >= 62 D) age >= 18 && age <= 62 Ans: D Section Ref: Special Topic 5.5 DeMorgans Laws Title: TB 5.75 Which of the following statements determines whether a person is ineligible for a junior or senior discount? Difficulty: Hard

You might also like