Programming Languages Chapter 1 Logic Errors Have Effects Execution Timed Logic

subject Type Homework Help
subject Pages 9
subject Words 1513
subject Authors Harvey Deitel, Paul Deitel

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Chapter 4 Control Statements: Part 1
Section 4.2 Algorithms
4.2 Q1: Which of the following is not an algorithm?
a. A recipe.
b. Operating instructions.
c. Textbook index.
d. Shampoo instructions (lather, rinse, repeat).
4.3 Q1: Which of the following is true?
a. Pseudocode is used to describe an algorithm.
b. Pseudocode is not an actual computer programming language.
c. Pseudocode is used to describe executable statements that will eventually be translated by the
programmer into a program.
d. All of the above.
4.4 Q1: Which of the following is not a benefit of “goto-less programming”?
a. Easier to debug and modify
b. Shorter
c. Clearer
d. More likely to be bug free
4.4 Q2: Which of the following is not a control structure:
a. Sequence structure.
b. Selection structure.
c. Repetition structure.
d. Declaration structure.
4.4 Q3: Which of the following is the shape of an action-state symbol?
a. Diamond.
b. Circle.
c. Rectangle with left and right sides replaced with arcs curving outward.
d. Rounded rectangle.
4.4 Q4: Which statement is false?
a. Unless directed otherwise, the computer executes Java statements one after the other in the order in
which they're written.
b. Activity diagrams normally show the Java code that implements the activity.
c. Like pseudocode, activity diagrams help programmers develop and represent algorithms.
d. The arrows in the activity diagram represent transitions, which indicate the order in which the actions
represented by the action states occur.
page-pf2
4.4 Q5: Which of the following is a double-selection control statement?
a. dowhile
b. for
c. ifelse
d. if
4.4 Q6: Which of the following is not a Java keyword?
a. do
b. next
c. while
d. for
4.5 Q1: What is output by the following Java code segment?
int temp = 200;
if (temp > 90)
System.out.println("This porridge is too hot.");
if (temp < 70)
System.out.println("This porridge is too cold.");
if (temp == 80)
System.out.println("This porridge is just right!");
a. This porridge is too hot.
b. This porridge is too cold.
c. This porridge is just right!
d. None of the above.
4.5 Q2: A decision symbol in an activity diagram takes the shape of a ________.
a. Diamond.
b. Rectangle.
c. Circle.
d. Triangle.
4.5 Q3: Which of the following is not represented graphically in activity diagrams for control structures?
a. Transition arrow.
b. Attribute.
page-pf3
c. Action state.
d. Decision symbol.
4.6 Q1: Which of the following statements about the conditional operator (?:) is false?
a. The conditional operator is a ternary operator, meaning that it takes three operands.
b. The first operand is a boolean expression.
c. The second operand is the result value if the condition evaluates to false.
d. The second operand is the result value if the condition evaluates to true.
4.6 Q2: What is output by the following Java code segment?
int temp = 180;
if (temp > 90)
{
System.out.println("This porridge is too hot.");
// cool down
temp = temp (temp > 150 ? 100 : 20);
}
else
{
if (temp < 70)
{
System.out.println("This porridge is too cold.");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
}
}
if (temp == 80)
System.out.println("This porridge is just right!");
a. This porridge is too hot.
b. This porridge is too cold.
This porridge is just right!
c. This porridge is just right!
d. None of the above.
page-pf4
4.6 Q3: Which of the following would not be used to clarify a dangling-else?
a. Indentation.
b. Parentheses ().
c. Braces {}.
d. Comment //.
4.6 Q4: The empty statement is denoted by what symbol?
a. Semicolon ;
b. Parentheses ()
c. Braces {}
d. Colon :
4.6 Q5: Which of the following statements is true?
a. Both syntax errors and logic errors are caught by the compiler.
b. Both syntax errors and logic errors have effects at execution time.
c. Syntax errors are caught by the compiler. Logic errors have effects at execution time.
d. Logic errors are caught by the compiler. Syntax errors have effects at execution time.
4.7 Q1: Which of the following statements is false?
a. You should not call methods from constructors.
b. Nested if statements can be useful for validating values.
c. Logical operators can express nested if statements more concisely.
d. One problem with calling methods from constructors is that it can lead to duplicated validation code.
4.8 Q1: What is output by the following Java code segment?
int temp = 180;
while (temp != 80)
{
if (temp > 90)
{
System.out.print("This porridge is too hot! ");
// cool down
temp = temp (temp > 150 ? 100 : 20);
}
else
{
if (temp < 70)
{
page-pf5
System.out.print(
"This porridge is too cold! ");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
}
}
}
if (temp == 80)
System.out.println("This porridge is just right!");
a. This porridge is too cold! This porridge is just right!
b. This porridge is too hot! This porridge is just right!
c. This porridge is just right!
d. None of the above.
4.8 Q2: Which of the following is not an error (either a syntax error or a logic error)?
a. Neglecting to include an action in the body of a while statement that will eventually cause the
condition to become false.
b. Spelling a keyword (such as while or if) with a capitalized first letter.
c. Using a condition for a while statement that is initially false.
d. An infinite loop.
4.8 Q3: In an activity diagram, the merge symbol has the same shape as what other symbol?
a. Decision symbol.
b. Action symbol.
c. Transition arrows.
d. Initial state.
4.9 Q1: Counter-controlled repetition is also known as:
a. Definite repetition
b. Indefinite repetition
c. Multiple-repetition structure
d. Double-repetition structure
4.9 Q2: How many times is the body of the loop below executed?
int counter = 1;
while (counter > 20)
{
// body of loop
counter = counter - 1;
} // end while
page-pf6
a. 19.
b. 20.
c. 21.
d. 0.
4.9 Q3: Where can local variables declared within a method’s body be used?
a. Only in that method between the line in which they were declared and the closing brace of that
method.
b. Same as (a), but not within while or if statements.
c. Only within while or if statements within the method in which they were declared.
d. Anywhere within the class.
4.9 Q4: Which statement is true?
a. Dividing two integers results in integer division.
b. With integer division, any fractional part of the calculation is lost.
c. With integer division, any fractional part of the calculation is truncated.
d. All of the above.
4.10 Q1: Which of the following terms is not used to refer to a sentinel value that breaks out of a while
loop?
a. signal value.
b. maximum value.
c. dummy value.
d. flag value.
4.10 Q2: Sentinel-controlled repetition is also known as:
a. Definite repetition.
b. Indefinite repetition.
c. Multiple repetition.
d. Double repetition.
4.10 Q3: Which of the following is not a common name for one of the three phases that a program often
can be split into using pseudocode?
a. Termination phase
b. Initialization phase
c. Processing phase
page-pf7
d. Action phase
4.10 Q4: Which of the following segments is a proper way to call the method readData four times?
a. double k = 0.0;
while (k != 4)
{
readData();
k = k + 1;
}
b. int i = 0;
while (i <= 4)
{
readData();
i = i + 1;
}
c. int i = 0;
while (i < 4)
{
readData();
}
d. int i = 0;
while (i < 4)
{
readData();
i = i + 1;
}
4.10 Q5: In an expression containing values of the types int and double, the ________ values are
________ to ________ values for use in the expression.
a. int, promoted, double.
b. int, demoted, double.
c. double, promoted, int.
d. double, demoted, int.
4.10 Q6: Which of the following statements is false?
page-pf8
a. To ensure that the operands in a mixed-type expression are of the same type, Java performs implicit
conversion on selected operands.
b. Cast operators are unary operators.
c. Cast operators associate from right to left and are one level lower in precedence than the multiplicative
operators.
d. Cast operators are formed by placing parentheses around the name of a type.
4.11 Q1: Local variables must be ________.
a. initialized when they're declared.
b. initialized before their values are used in an expression.
c. declared and initialized in two steps.
d. declared at the top of the method’s body.
4.11 Q2: Which of the following statements is true?
a. A while statement cannot be nested inside another while statement.
b. An if statement cannot be nested inside another if statement.
c. A while statement cannot be nested inside an if statement.
d. None of the above is true.
4.12 Q1: Which of the following code segments does not increment val by 3:
a. val += 3;
b. val = val + 1;
val = val + 1;
val = val + 1;
c. c = 3;
val = val + (c == 3 ? 2 : 3);
d. All of the above increment val by 3.
4.12 Q2: What does the expression x %= 10 do?
a. Adds 10 to the value of x, and stores the result in x.
b. Divides x by 10 and stores the remainder in x.
c. Divides x by 10 and stores the integer result in x.
d. None of the above.
page-pf9
Section 4.13 Increment and Decrement Operators
4.13 Q1: Which of the following operators associates from left to right?
a. =
b. ?:
c. %=
d. /
4.13 Q2: What is the result value of c at the end of the following code segment?
int c = 8;
c++;
++c;
c %= 5;
a. 0.
b. 1.
c. 3.
d. None of the above.
4.14 Q1: Java is considered a strongly typed language because:
a. The primitive types in Java are portable across all computer platforms that support Java.
b. Java requires all variables to have a type before they can be used in a program.
c. Instance variables of the primitive types are automatically assigned a default value.
d. All of the above.
4.14 Q2: Which of the following is not a primitive type?
a. char
b. float
c. String
d. int
4.14 Q3: Which primitive type can hold the largest value?
a. int
b. long
c. float
d. double
4.14 Q4: What is the size in bits of an int?
a. 8
b. 16
c. 32
d. 64
4.15 Q1: In Java graphics, coordinate units are measured in ________.
page-pfa
a. pixlets.
b. pixels.
c. points.
d. pikels.
4.15 Q2: Keyword ________ indicates the inheritance relationship.
a. extends
b. inherits
c. super
d. parent

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.