Programming in C# Chapter 5 Review Questions

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

&&

The ____________ operator represents the logical AND. a. ++ b. | | c. && d. @ e. none of the above

15

After execution of the following code, what will be the value of inputValue? int inputValue = 0; if (inputValue > 5) inputValue += 5; else if (inputValue > 2) inputValue += 10; else inputValue += 15; a. 15 b. 10 c. 25 d. 0 e. 5

27

Consider the following if statement, which is syntactically correct, but uses poor style and indentation: if (x >= y) if (y > 0) x = x * y; else if (y < 4) x = x - y; Assume that x and y are int variables containing the values 9 and 3, respectively, before execution of the preceding statement. After execution of the statement, what value does x contain? a. 9 b. 1 c. 6 d. 27 e. none of the above

every time the program is executed

Examine the code to complete the following question. (Be careful.) if (A == B); C = 3; a. when A is equal to B b. when A is not equal to B c. never d. every time the program is executed e. not enough information is given

Blue, blue, sail on through Green, green, nice and clean

Given the following segment of code, what will be the output? int x = 5; if (x == 2) Console.WriteLine("Brown, brown, run aground."); else Console.WriteLine("Blue, blue, sail on through."); Console.WriteLine("Green, green, nice and clean."); a. Brown, brown, run aground. b. Blue, blue, sail on through. c. Brown, brown, run aground. Blue, blue, sail on through. d. Blue, blue, sail on through. Green, green, nice and clean. e. none of the above

if (control == 11)

Given the switch statement, which of the following would be the first if statement to replace the first test in the switch? switch (control) { case 11 : Console.WriteLine("eleven"); break; case 12 : Console.WriteLine("twelve"); break; case 16 : Console.WriteLine("sixteen"); break; } a. if (case = 11) b. if (case == 11) c. if (control == 11) d. if (switch == 11) e. none of the above

curly braces

If you intend to place a block of statements within an if statement, you must use around the block. a. parentheses b. square brackets c. quotation marks d. curly braces e. none of the above

detracts from its readability

Incorrect use of spacing with an if statement: a. detracts from its readability b. causes a syntax error message c. can change the program logic d. causes a logic error message e. all of the above

true or false

The result of the expression if (aValue == 10) is: a. true or false b. 10 c. an integer value d. aValue e. determined by an input statement

a and b are correct

The string data type can be used: a. as an operand for the == or != b. as an expression in the switch statement to be evaluated c. as an operand for the > or < operator d. a and b are correct e. all of the above

used as part of an assignment statement

The symbol (=) is: a. the operator used to test for equality b. used for comparing two items c. used as part of an assignment statement d. considered a logical compound operator e. all of the above

1 1

What does the following program segment display? int f = 7, s = 15; f = s % 2; if (f != 1) { f = 0; s = 0; } else if (f == 2) { f = 10; s = 10; } else { f = 1; s = 1; } Console.WriteLine(" " + f + " " + s); a. 7 15 b. 0 0 c. 10 10 d. 1 1 e. none of the above

That's a high score! This is a test question!

What is displayed when the following code executes? score = 40; if (score > 95) Console.WriteLine("Congratulations!"); Console.WriteLine("That's a high score!"); Console.WriteLine("This is a test question!"); a. This is a test question! b. Congratulations! That's a high score! This is a test question! c. That's a high score! This is a test question! d. Congratulations! That's a high score! e. none of the above

3

What is the output for total after the following segment of code executes? int num = 4, total = 0; switch (num) { case 1: case 2: total = 5; break; case 3: total = 10; break; case 4: total = total + 3; break; case 8: total = total + 6; break; default: total = total + 4; break; } Console.WriteLine("The value of total is " + total); a. 0 b. 3 c. 13 d. 28 e. none of the above

2000

What is the result of the following conditional expression when aValue = 100 and bValue = 7? result = aValue > bvalue + 100 ? 1000 : 2000; a. 0 b. 1000 c. 2000 d. 7 e. none of the above

You failed the test! You passed the test!

What will be displayed from executing the following segment of code? You may assume testScore has a value of 90. int testScore; if (testScore < 60); // Note the semicolon. Console.WriteLine("You failed the test!"); if (testScore > 60) Console.WriteLine("You passed the test!"); else Console.WriteLine("You need to study for " + "the next test!"); a. You failed the test! b. You passed the test! c. You failed the test! You passed the test! d. You failed the test! You need to study for the next test! e. none of the above

a + 7

Which expression is evaluated first in the following statement? if (a > b && c == d | | a == 10 && b > a + 7) a. a > b b. b && c c. d | | a d. a + 7 e. none of the above

AND

Which logical operator (op) is defined by the following table? (T and F denote true and false.) P Q P op Q T T T T F F F T F F F F a. NOT b. AND c. OR d. not enough information is given e. none of the above

Logical OR yields true if either or both of the operands are true

Which of the following statements about logical operators is correct? a. Logical AND yields true if and only if both of its operands are either true or false. b. Logical OR yields true if either or both of its operands are true. c. Logical OR is represented in C# by && . d. Logical NOT is represented in C# by | . e. none of the above

if (code == 'C') Console.WriteLine ("This is a check");

Which statement in C# allows you to do the following: properly check the variable code to determine whether it contains the character C, and if it does, display ''This is a check'' and then advance to a new line? a. if code is equal to C Console.WriteLine("This is a check"); b. if (code = "C") Console.WriteLine("This is a check"); c. if (code == 'C') Console.WriteLine("This is a check"); d. if (code == C) Console.WriteLine("This is a check"); e. none of the above


Set pelajaran terkait

Texas History - Goliad/San Jacinto

View Set

Pharm Test week 5 wvjc CH 60-65,68-69

View Set

FLORIDA STATUTES, RULES, AND REGULATIONS COMMON TO ALL LINES

View Set