You are on page 1of 10

Java - Homework 5 - CHAPTER 4

Study online at https://quizlet.com/_4hltih

1. All of the above. Which of the following is true?

Pseudocode is used to describe an algorithm.

Pseudocode is not an actual computer programming lan-


guage.

Pseudocode is used to describe executable statements


that will eventually be translated by the programmer into a
program.

All of the above.

2. Indefinite repeti- Sentinel-controlled repetition is also known as:


tion.
Definite repetition.
Indefinite repetition.
Multiple repetition.
Double repetition.

3. Activity dia- Which statement is false?


grams normally
show the Java Unless directed otherwise, the computer executes Java
code that imple- statements one after the other in the order in which they're
ments the activi- written.
ty.
Activity diagrams normally show the Java code that imple-
ments the activity.

Like pseudocode, activity diagrams help programmers de-


velop and represent algorithms.

The arrows in the activity diagram represent transitions,


which indicate the order in which the actions represented
by the action states occur.

4. Declaration Which of the following is not a control structure:


structure.
Sequence structure.
1 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
Selection structure.
Repetition structure.
Declaration structure.

5. The second Which of the following statements about the conditional


operand is the re- operator (?:) is false?
sult value if the
condition evalu- The conditional operator is a ternary operator, meaning
ates to false. that it takes three operands.

The first operand is a boolean expression.

The second operand is the result value if the condition


evaluates to false.

The second operand is the result value if the condition


evaluates to true.

6. Which of the following statements is false? (please check


the answer)

You should not call methods from constructors.

Nested if statements can be useful for validating values.

Logical operators can express nested if statements more


concisely.

One problem with calling methods from constructors is


that it can lead to duplicate validation code.

7. if...else Which of the following is a double-selection control state-


ment?

Do...while
for
if...else
if

8.
2 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
Java requires all Java is considered a strongly typed language because:
variables to have
a type before The primitive types in Java are portable across all comput-
they can be used er platforms that support Java.
in a program.
Java requires all variables to have a type before they can
be used in a program.

Instance variables of the primitive types are automatically


assigned a default value.

All of the above.

9. Textbook index. Which of the following is not an algorithm?

A recipe.
Operating instructions.
Textbook index.
Shampoo instructions (lather, rinse, repeat).

10. maximum value. Which of the following terms is not used to refer to a
sentinel value that breaks out of a while loop?

signal value.
maximum value.
dummy value.
flag value.

11. next Which of the following is not a Java keyword?

do
next
while
for

12. Attribute. Which of the following is not represented graphically in


activity diagrams or control structures?

Transition arrow.
Attribute.
3 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
Action state.
Decision symbol.

13. Which of the following statements is true?

Both syntax errors and logic errors are caught by the


compiler.

Both syntax errors and logic errors have effects at execu-


tion time.

Syntax errors are caught by the compiler. Logic errors


have effects at execution time.

Logic errors are caught by the compiler. Syntax errors


have effects at execution time.

14. 0 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

19.
20.
21.
0.

15. Divides x by 10 What does the expression x %= 10 do?


and stores the re-
mainder in x. Adds 10 to the value of x, and stores the result in x.
Divides x by 10 and stores the remainder in x.
Divides x by 10 and stores the integer result in x.
None of the above.

16. Action phase 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?
4 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih

Termination phase
Initialization phase
Processing phase
Action phase

17. int, promoted, In an expression containing values of the types int and
double. double, the ________ values are ________ to ________
values for use in the expression.

int, promoted, double.


int, demoted, double.
double, promoted, int.
double, demoted, int.

18. initialized before Local variables must be ________.


their values are
used in an ex- initialized when they're declared.
pression initialized before their values are used in an expression.
declared and initialized in two steps.
declared at the top of the method's body.

19. Diamond. A decision symbol in an activity diagram takes the shape


of a ________.

Diamond.
Rectangle.
Circle.
Triangle.

20. Definite repeti- Counter-controlled repetition is also known as:


tion
Definite repetition
Indefinite repetition
Multiple-repetition structure
Double-repetition structure

21. Decision symbol. In an activity diagram, the merge symbol has the same
shape as what other symbol?

5 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
Decision symbol.
Action symbol.
Transition arrows.
Initial state.

22. None of the Which of the following statements is true?


above is true.
A while statement cannot be nested inside another while
statement.
An if statement cannot be nested inside another if state-
ment.
A while statement cannot be nested inside an if statement.
None of the above is true.

23. This porridge is What is output by the following Java code segment?
too hot.
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!");

This porridge is too hot.


This porridge is too cold.
This porridge is just right!
None of the above.

24. double k = 0.0; Which of the following segments is a proper way to call the
while (k != 4) method readData four times?
{
readData(); k = k a.
+ 1; double k = 0.0;
} while (k != 4)
{

6 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
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;
}

25. Semicolon ; The empty statement is denoted by what symbol?

Semicolon ;
Parentheses ()
Braces {}
Colon :

26. Only in that Where can local variables declared within a method's
method between body be used?
the line in which
they were de- Only in that method between the line in which they were
clared and the declared and the closing brace of that method.

7 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
closing brace of Same as (a), but not within while or if statements.
that method.
Only within while or if statements within the method in
which they were declared.

Anywhere within the class.

27. Cast operators Which of the following statements is false?


associate from
right to left and To ensure that the operands in a mixed-type expression
are one level low- are of the same type, Java performs implicit conversion
er in precedence on selected operands.
than the multi-
plicative opera- Cast operators are unary operators.
tors.
Cast operators associate from right to left and are one lev-
el lower in precedence than the multiplicative operators.

Cast operators are formed by placing parentheses around


the name of a type.

28. / Which of the following operators associates from left to


right?

=
?:
%=
/

29. Parentheses (). Which of the following would not be used to clarify a
dangling-else?

Indentation.
Parentheses ().
Braces {}.
Comment //.

30. All of the above. Which statement is true?

Dividing two integers results in integer division.


8 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih

With integer division, any fractional part of the calculation


is lost.

With integer division, any fractional part of the calculation


is truncated.

All of the above.

31. Using a condi- Which of the following is not an error (either a syntax error
tion for a while or a logic error)?
statement that is
initially false. Neglecting to include an action in the body of a while state-
ment that will eventually cause the condition to become
false.

Spelling a keyword (such as while or if) with a capitalized


first letter.

Using a condition for a while statement that is initially false.

An infinite loop.

32. None of the What is output by the following Java code segment?
above.
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

9 / 10
Java - Homework 5 - CHAPTER 4
Study online at https://quizlet.com/_4hltih
temp = temp + (temp < 50 ? 30 : 20);
}
}

if (temp == 80)
System.out.println("This porridge is just right!");

This porridge is too hot.


This porridge is too cold.
This porridge is just right!
This porridge is just right!
None of the above.

10 / 10

You might also like