Review: Boolean Logic and Following Code Segment

Only available on StudyMode
  • Download(s) : 1268
  • Published : November 30, 2011
Open Document
Text Preview
Review Questions – Chapter 5

1. The logical structure in which one instruction occurs after another with no branching is a ______A______.

a. sequence

b. selection

c. loop

d. case

2. Which of the following is typically used in a flowchart to indicate a decision? C.
a. square

b. rectangle

c. diamond

d. oval

3. Which of the following is not a type of if statement? C.

a. single-alternative if

b. dual-alternative if

c. reverse if

d. nested if

4. A decision is based on a(n) _____A_______ value.

a. Boolean

b. absolute

c. definitive

d. convoluted

5. In Java, the value of (4 > 7) is ______C______.

a. 4

b. 7

c. true

d. false

6. Assuming the variable q has been assigned the value 3, which of the following statements prints XXX? A.

a. if(q > 0) System.out.println("XXX");

b. if(q > 7); System.out.println("XXX");

c. Both of the above statements print XXX.

d. Neither of the above statements prints XXX.

7. What is the output of the following code segment? C.

t = 10;

if(t > 7)

{

System.out.print("AAA");

System.out.print("BBB");

}

a. AAA

b. BBB

c. AAABBB

d. nothing

Because the tested expression is true, both statements in the block execute.

8. What is the output of the following code segment? C.

t = 10;

if(t > 7)

System.out.print("AAA");

System.out.print("BBB");

a. AAA

b. BBB

c. AAABBB

d. nothing

The tested expression is true, so AAA prints. The second print statement is a stand-alone statement, so BBB also prints.

9. What is the output of the following code segment? D.

t = 7;

if(t > 7)

System.out.print("AAA");

System.out.print("BBB");

a. AAA

b. BBB

c. AAABBB

d. nothing

The tested expression is false, so AAA does not print. The statement that prints BBB is not dependent on the if statement, so BBB prints.

10. When you code an if statement within another if statement, as in the following, then the if statements are ____C________:

if(a > b)

if(c > d)x = 0;

a. notched

b. nestled

c. nested

d. sheltered

11. The operator that combines two conditions into a single Boolean value that is true only when both of the conditions are true, but is false otherwise, is _____D_______.

a. $$

b. !!

c. ||

d. &&

12. The operator that combines two conditions into a single Boolean value that is true when at least one of the conditions is true is _____C_______.

a. $$

b. !!

c. ||

d. &&

13. Assuming a variable f has been initialized to 5, which of the following statements sets g to 0? D.

a. if(f > 6 || f == 5) g = 0;

b. if(f < 3 || f > 4) g = 0;

c. if(f >= 0 || f < 2) g = 0;

d. All of the above statements set g to 0.

14. Which of the following groups has the lowest operator precedence? D.

a. relational

b. equality

c. addition

d. logical OR

15. Which of the following statements correctly prints the names of voters who live in district 6 and all voters who live in district 7? C.

a. if(district == 6 || 7)

System.out.println("Name is " + name);

b. if(district == 6 || district == 7)

System.out.println("Name is " + name);

c. if(district = 6 && district == 7)

System.out.println("Name is " + name);

d. two of these

16. Which of the following prints “Error” when a student ID is less than 1000 or more than 9999? D.
a. if(stuId < 1000) if(stuId > 9999)

System.out.println("Error");

b. if(stuId < 1000 && stuId > 9999)

System.out.println("Error");

c. if(stuId < 1000)

System.out.println("Error");

else if(stuId > 9999)

System.out.println("Error");

d. Two of these are correct.

17. You can use...
tracking img