Chapter 3 CPS

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

&&, ||, and ! are __________. a. relational operators b. logical operators c. conditional operators d. ternary operators

b

How does the character 'A' compare to the character 'B'? a. 'A' is greater than 'B' b. 'A' is less than 'B' c. 'A' is equal to 'B' d. You cannot compare characters

b

This section of a switch statement is branched to if none of the case expressions match the switch expression. a. else b. default c. case d. otherwise

b

This type of expression has a value of either true or false a. binary expression b. decision expression c. unconditional expression d. boolean expression

b

The conditional operator takes this many operands. a. one b. two c. three d. four

c

This determines whether two different String objects contain the same string. a. the == operator b. the = operator c. the equals method d. the stringCompare method

c

True or False: The = operator and the == operator perform the same operation.

False

True or 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.

This is an empty statement that does nothing. a. missing statement b. virtual statement c. null statement d. conditional statement

c

You can use this method to display formatted output in a console window. a. Format.out.println b. Console.format c. System.out.printf d. System.out.formatted

c

True or False: The scope of a variable is limited to the block in which it is defined.

True

True or False: 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

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

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

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.

&&

AND Connects two boolean expressions into one. Both expressions must be true for the overall expression to be true.

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.

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.

!

NOT The ! operator reverses the truth of a boolean expression. If it is applied to an expression that is true, the operator returns false. If it is applied to an expression that is false, the operator returns true.

l l

OR Connects two boolean expressions into one. One or both expressions must be true for the overall expression to be true. It is only necessary for one to be true, and it does not matter which one.

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.

True or False: A conditionally executed statement should be indented one level from the if clause.

True

True or False: All lines in a conditionally executed block should be indented one level.

True

>, <, and == are __________. a. relational operators b. logical operators c. conditional operators d. ternary operators

a

An else clause always goes with __________. a. the closest previous if clause that doesn't already have its own else clause b. the closest if clause c. the if clause that is randomly selected by the compiler d. none of these

a

This is a boolean variable that signals when some condition exists in the program. a. flag b. signal c. sentinel d. siren

a

This is an if statement that appears inside another if statement. a. nested if statement b. tiered if statement c. dislodged if statement d. structured if statement

a

When determining whether a number is inside a range, it's best to use this operator. a. && b. ! c. || d. ? :

a

sequence structure

a set of statements that execute in the order that they appear

The if statement is an example of a_______ A. Sequence Structure B. Decision Structure C. Pathway Structure D. Class Structure

d

To create a block of statements, you enclose the statements in these. a. parentheses() b. square brackets [] c. angled brackets <> d. braces {}

d


Kaugnay na mga set ng pag-aaral

Live Virtual Machine Lab 12.1: Module 12 Authentication and Authorization Implementation Techniques

View Set

Pang-abay - Panang-ayon o Pananggi o Panggaano2

View Set

Unit 3 AP GOV - MCQ Practice (AP Progress Check)

View Set