Chapter 4

¡Supera tus tareas y exámenes ahora con Quizwiz!

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.

A. Decision symbol.

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.

A.) 0.

Counter-controlled repetition is also known as: A.) Definite repetition B.) Indefinite repetition C.) Multiple-repetition structure D.) Double-repetition structure

A.) Definite repetition

A decision symbol in an activity diagram takes the shape of a ________. A.) Diamond. B.) Rectangle. C.) Circle. D.) Triangle

A.) Diamond.

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.

A.) Only in that method between the line in which they were declared and the closing brace of that method.

The empty statement is denoted by what symbol? A.) Semicolon ; B.) Parentheses () C.) Braces {} D.) Colon :

A.) Semicolon ;

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.

A.) This porridge is too hot.

Keyword ________ indicates the inheritance relationship. A.) extends B.) inherits C.) super D). parent

A.) extends

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.

A.) int, promoted, double

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.

B.) Activity diagrams normally show the Java code that implements the activity.

Which of the following is not represented graphically in activity diagrams for control structures? A.) Transition arrow. B.) Attribute. C.) Action state. D.) Decision symbol.

B.) Attribute.

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.

B.) Divides x by 10 and stores the remainder in x

Sentinel-controlled repetition is also known as: A.) Definite repetition. B.) Indefinite repetition. C.) Multiple repetition. D.) Double repetition.

B.) Indefinite repetition.

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.

B.) Java requires all variables to have a type before they can be used in a program

Which of the following would not be used to clarify a dangling-else? A.) Indentation. B.) Parentheses (). C.) Braces {}. D.) Comment //.

B.) Parentheses ().

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

B.) Shorter

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) { 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.

B.) This porridge is too hot! This porridge is just right!

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.

B.) initialized before their values are used in an expression.

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.

B.) maximum value.

Which of the following is not a Java keyword? A.) do B.) next C.) while D.) for

B.) next

In Java graphics, coordinate units are measured in ________. A.) pixlets. B.) pixels. C.) points. D.) pikels.

B.) pixels.

Which of the following is not an algorithm? A.) A recipe. B.) Operating instructions. C) Textbook index. D) Shampoo instructions (lather, rinse, repeat)

C) Textbook index. A textbook index contains useful information, but does not specify actions and the order in which they are to be performed.

What is the size in bits of an int? A.) 8 B.) 16 C.) 32 D.) 64

C.) 32

Which of the following statements is false? 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.

C.) Cast operators associate from right to left and are one level lower in precedence than the multiplicative operators.

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.

C.) Rectangle with left and right sides replaced with arcs curving outward.

Which of the following is not a primitive type? A.) char B.) float C.) String D.) int

C.) String

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.

C.) Syntax errors are caught by the compiler. Logic errors have their effects at execution time.

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.

C.) The second operand is the result value if the condition evaluates to false.

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.

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

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.

C.) c = 3; val = val + (c == 3 ? 2 : 3);

Which of the following is a double-selection control statement? A.) do...while B.) for C.) if...else D.) if

C.) if...else

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.

D. All of the above.

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; }

D.) int i = 0; while (i < 4) { readData(); i = i + 1; }

Which of the following operators associates from left to right? A.) = B.) ?: C.) %= D.) /

D.) /

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 A.) 19. B.) 20. C.) 21. D. 0.

D.) 0.

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 D.) Action phase

D.) Action phase

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.

D.) All of the above.

Which of the following is not a control structure: A.) Sequence structure. B.) Selection structure. C.) Repetition structure. D.) Declaration structure.

D.) Declaration structure.

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.

D.) None of the above is true.

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.

D.) None of the above. (The output will be This porridge is too hot. This porridge is just right!)

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

D.) One problem with calling methods from constructors is that it can lead to duplicated validation code. Actually, you should not call methods from constructors and this good practice leads to duplicate validation code.

Which primitive type can hold the largest value? A.) int B.) long C.) float D.) double

D.) double


Conjuntos de estudio relacionados

FIN 2100 Chapter 3 Additional Questions

View Set

Physiology 2, exam 1 practice questions

View Set

Chapter 1 Network Defense Fundamentals

View Set

Care of Musculoskeletal Patients

View Set