the java

4118 words 17 pages
Java Software Solutions: Foundations of Program Design, 6e (Lewis/Loftus)
Chapter 5 Conditionals and Loops

Multiple-Choice Questions

1) The idea that program instructions execute in order (linearly) unless otherwise specified through a conditional statement is known as
A) boolean execution
B) conditional statements
C) try and catch
D) sequentiality
E) flow of control
Answer: E
Explanation: E) The "flow of control" describes the order of execution of instructions. It defaults to being linear (or sequential) but is altered by using control statements like conditionals and loops.

2) Of the following if statements, which one correctly executes three instructions if the condition is true?
A) if (x < 0) a = b *
…show more content…

Further, because you have to enumerate each possible value being tested, the switch statement only makes sense if the number of values being tested is a small number.

9) Assume that count is 0, total is 20 and max is 1. The following statement will do which of the following? if (count != 0 && total / count > max) max = total / count;
A) The condition short circuits and the assignment statement is not executed
B) The condition short circuits and the assignment statement is executed without problem
C) The condition does not short circuit causing a division by zero error
D) The condition short circuits so that there is no division by zero error when evaluating the condition, but the assignment statement causes a division by zero error
E) The condition will not compile because it uses improper syntax
Answer: A
Explanation: A) Since count is 0, (count != 0) is false. Because the left-hand side of an && condition is false, the condition is short circuited, and so the right-hand side is not evaluated. Thus, a potential division by zero error is avoided. Because the condition is false, the statement max = total / count is not executed, again avoiding a potential

Related

  • Cis 210 Term Paper
    2658 words | 11 pages
  • Sequential vs. Event-Driven Programming
    1845 words | 8 pages
  • Business Requirements Report
    4739 words | 19 pages
  • Planet of Life
    1939 words | 8 pages
  • Development of a Student Management System
    2668 words | 11 pages
  • Covert Action
    3067 words | 13 pages
  • Tony's Chips
    1949 words | 8 pages
  • FYT2
    2164 words | 9 pages
  • Modernization of NTUC Income
    1406 words | 6 pages
  • Susan Munro, Service Customer Analysis
    1658 words | 7 pages