CH 3 Java

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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

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

The if statement is an example of a __________.

decision structure

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

default

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

flag

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'

>, <, and == are __________.

relational operators

// Warning! This code contains ERRORS! if (x == 1); y = 2; else if (x == 2); y = 3; else if (x == 3); y = 4;

Each if clause is prematurely terminated by a semicolon.

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

System.out.printf

// Warning! This code contains an ERROR! if (average = 100) System.out.println("Perfect Average!");

The = operator should be == .

&&, ||, and ! are __________.

logical operators

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

The following statement should determine whether x is not greater than 20. What is wrong with it? if (!x > 20)

The ! operator is only applied to the variable x , not the expression. The code should read: if (!(x > 20))

The following statement should assign 0 to z if a is less than 10; otherwise, it should assign 7 to z. What is wrong with it? z = (a < 10) : 0 ? 7;

The : and ? are reversed in their positions. The statement should read: z = (a < 10) ? 0 : 7;

// Warning! This code contains ERRORS! switch (score) { case (score > 90): grade = 'A'; break; case(score > 80): grade = 'b'; break; case(score > 70): grade = 'C'; break; case (score > 60): grade = 'D'; break; default: grade = 'F'; }

The case expressions cannot have relational operators. They must be integer expressions.

// Warning! This code contains ERRORS! if (num2 == 0) System.out.println("Division by zero is not possible."); System.out.println("Please run the program again "); System.out.println("and enter a number besides zero."); else Quotient = num1 / num2; System.out.print("The quotient of " + Num1); System.out.print(" divided by " + Num2 + " is "); System.out.println(Quotient);

The conditionally-executed blocks of code should be enclosed in braces.

The following statement should determine whether count is within the range of 0 through 100. What is wrong with it?

The statement should use the operator instead of the || operator.

The following statement should determine whether count is outside the range of 0 through 100. What is wrong with it? if (count < 0 && count > 100)

The statement should use the || operator instead of the operator.

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 is an if statement that appears inside another if statement.

nested if statement

This is an empty statement that does nothing

null statement

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

The conditional operator takes this many operands.

three


Set pelajaran terkait

Chapter 2.6: Nutrition Standards

View Set

N5451 Skills Lab > Video Quizzes > Module 9. Skin Integrity and Wound Care

View Set

Chapter 3 Government Sections 1,2, and 3

View Set