CPS Chapter 3 MC/TF/Short Answer

Ace your homework & exams now with Quizwiz!

This type of expression has a value of either true or false.

boolean expression

To create a block of statements, you enclose the statements in these.

braces {}

This section of a switch statement is branched to if none of the case expressions match the switch expression.

Default

The = operator and the == operator perform the same operation.

False

When an if statement is nested in the else clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

False

Explain why a misplaced semicolon can cause an if statement to operate incorrectly.

If you inadvertently terminate an if statement with a semicolon, the compiler will assume that you are placing a null statement there. The null statement, which is an empty statement that does nothing, will become the conditionally executed statement. The statement that you intended to be conditionally executed will be disconnected from the if statement and will always execute.

When an if statement is nested in the if clause of another statement, the only time the inner if statement is executed is when the boolean expression of the outer if statement is true.

True

The scope of a variable is limited to the block in which it is defined.

True.

This is a boolean variable that signals when some condition exists in the program.

flag

&&, ||, and ! are ________.

logical operators

This is an if statement that appears inside another if statement.

nested if statement

This is an empty statement that does nothing.

null statement

When determining whether a number is inside a range, it's best to use this operator.

&&

How does the character 'A' compare to the character 'B'?

'A' is less than 'B'

When does a constructor execute? What is its purpose?

A constructor executes automatically when an object is created. Its purpose is to initialize the object's attributes with data and perform any necessary startup operations.

Explain the purpose of a flag variable. Of what data type should a flag variable be?

A flag is a boolean variable that signals when some condition exists in the program. When the flag variable is set to false, it indicates the condition does not yet exist. When the flag variable is set to true, it means the condition does exist.

Why is it good advice to indent all the statements inside a set of braces?

By indenting the conditionally executed statements, you are causing them to stand out visually. This is so you can tell at a glance what part of the program the if statement executes.

Explain what is meant by the phrase "conditionally executed."

Conditionally executed code is executed only under a condition, such as an expression being true.

Briefly describe how the && operator works.

It takes two boolean expressions as operands and creates a boolean expression that is true only when both subexpressions are true.

Briefly describe how the || operator works.

It takes two boolean expressions as operands and creates a boolean expression that is true when either of the subexpressions are true.

You can use this method to display formatted output in a console window.

System.out.printf

What happens when you compare two String objects with the == operator?

The memory addresses of the two String objects are compared.

What risk does a programmer take when not placing a trailing else at the end of an if-else-if statement?

There is no default action that takes place when none of the if clauses' boolean expressions are true.

Why are the relational operators called relational?

They determine whether a specific relationship exists between two values. The relationships are greater-than, less-than, equal-to, not equal-to, greater-than or equal-to, and less-than or equal-to.

The conditional operator takes this many operands.

Three

A conditionally executed statement should be indented one level from the if clause.

True

All lines in a conditionally executed block should be indented one level.

True

The if statement is an example of a ________.

decision structure

>, <, and == are ________.

relational operators

An else clause always goes with ________.

the closest previous if clause that doesn't already have its own else clause

This determines whether two different String objects contain the same string.

the equals method


Related study sets

Health Law and Policy (Chapter 9)

View Set

RN study (Evolve) - Med Surg - Cardio+Medication

View Set

ADN 125 Chapter 2: Theory, Research, and Evidence-Informed Practice

View Set

BIO 128 - Chapter 19 The Evolution of Populations

View Set