You are on page 1of 3

INFO1150 Guided Reading Assignment Chapter 3-3: The Boolean or Logical Operators and comparing String objects Read Chapter

2, pages 135-149. For each question, type in your answer to the following questions in the spaces provided after each question. 1) What are the two binary logical operators provided by Java, and what symbols are used to represent them?

2) What is the one unary logical operator provided by Java, and what symbol is used to represent it?

3) When testing two conditions using the AND operator, what is the only circumstance in which the overall Boolean expression will evaluate to true?

4) When testing two conditions using the AND operator, what are the circumstance in which the overall Boolean expression will evaluate to false?

5) How can using the && operator help to simplify a program?

6) Re-write the nested if statement used in figure 10 on page 122 as a single if statement using a Boolean AND operator.

7) When testing two conditions using the OR operator, what are the circumstances in which the overall Boolean expression will evaluate to true?

8) When testing two conditions using the OR operator, what is the only circumstance in which the overall Boolean expression will evaluate to false?

9) Examine the code example near the top of page 139 where the logic of the OR operator is being explained. Is this code an example of an “inside the fence” or “outside the fence” check?

©FC2012

1

how must you do it? 18) What does the String method equals( ) actually do? ©FC2012 2 . that an outside the fence check uses the OR operator. 16) If you try to test two string objects using the “= =” equality operator. then you can deduce that an inside the fence check must use the AND operator. Do the logical operators for AND and OR have a higher or lower precedence than the arithmetic operators for multiplication and addition? 14) Examine the code example near the bottom of page 142 that is using an && operator. 11) What is the effect of the negation operator (the exclamation mark ! or “bang” operator) when it is applied to any Boolean variable or expression? 12) Of the three logical operators.10) Remember this saying: “OUTSIDE CHECK USES OR!” If you remember this. which one has the highest precedence? Which one has the lowest precedence? 13) Look at table 10 on page 142. Is this an “inside the fence” or “outside the fence” range check? How do you know? (SEE QUESTION 10!) 15) Look at checkpoints 16 through 19 on page 143 and answer each one. what is it that you are actually comparing? 17) If you want to compare two string objects to see if the letters that they contain are identical.

What happens if the two strings being compared are not the same length? 21) If you want to compare two strings but don’t care about the case of the letters. ©FC2012 3 . and 23 and answer each one of them. what methods should you use? 22) Look at checkpoint questions 21. and what value does it return? 20) Look at figure 23 on page 147 for a detailed description of how the compareTo( ) method actually works. 22.19) What does the String method compareTo( ) do? How does it work.