Programming Fundamentals I (Chapter 3)

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

An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement. Question options: True False

False

Programs never need more than one path of execution. Question options: True False

False

When testing for character values, the switch statement does not test for the case of the character. Question options: True False

False

A local variable's scope always ends at the closing brace of the block of code in which it is declared. Question options: True False

True

Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left. Question options: True False

True

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 1250; char cust = 'N'; if (purchase > 1000) if (cust == 'Y') discountRate = .05; else discountRate = .04; else if (purchase > 750) if (cust == 'Y') discountRate = .04; else discountRate = .03; else discountRate = 0; a) .04 b) .03 c) .05 d) 0

a) .04

What will be printed when the following code is executed? double x = 45678.259; DecimalFormat formatter = new DecimalFormat("#,###,##0.00"); System.out.println(formatter.format(x)); a) 45,678.26 b) 45,678.3 c) 0,045,678.26 d) 45678.259

a) 45,678.26

What does the following code display? int d = 9, e = 12; System.out.printf("%d %d\n", d, e); Question options: a) 9 12 b) %9 %12 c) %d 9 d) %d %d

a) 9 12

This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets: a) Unicode. b) Java. c) ASCII. d) None of the above.

a) Unicode

If chr is a character variable, which of the following if statements is written correctly? a) if (chr == 'a') b) if (chr = 'a') c) if (chr = "a") d) if (chr == "a")

a) if (chr == 'a' )

What would be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = .08; break; case 'B': discountRate = .06; case 'C': discountRate = .04; default: discountRate = 0.0; } a) .04 b) 0.0 c) .08 d) .06

b) 0.0

The switch statement is a: a) Sequence structure. b) Multiple alternative decision structure. c) Test expression. d) Nested decision structure.

b) Multiple alternative decision structure

Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B? a) if (chr < 'B') b) if (chr != 'B') c) if (chr > 'B') d) if (chr != "B")

b) if ( chr != 'B' )

What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250; a) 200 b) 1250 c) 1000 d) 500 e) 750

c) 1000

This type of operator determines whether a specific relationship exists between two values: a) Unary b) Logical c) Relational d) Mathematical

c) Relational

A block of code is enclosed in a set of: a) parentheses ( ) b) double quotes " " c) brackets [ ] d) braces { }

c) braces { }

The expression tested by an if statement must evaluate to: a) 0 or 1 b) t or f c) true or false d) +1 or -1

c) true or false

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase = 100; if (purchase > 1000) discountRate = .05; else if (purchase > 750) discountRate = .03; else if (purchase > 500) discountRate = .01; a) .03 b) .01 c) .05 d) 0.0

d) 0.0

What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; } a) 30 b) 25 c) 5 d) 20

d) 20

If you prematurely terminate an if statement with a semicolon, the compiler will: a) Assume you are placing a null statement there. b) Not display an error message. c) All of the above. d) None of the above.

d) All of the above.


Kaugnay na mga set ng pag-aaral

AFLTA State Competition: Spanish Culture Bowl

View Set

ways to say many (beberapa kata untuk mengatakan jumlah)

View Set