Introduction to Java Programming: Ch. 4 quiz

Ace your homework & exams now with Quizwiz!

T or F: Including a space between the relational operators >=, <=, ==, and != causes a syntax error.

t

T or F: You can always convert a switch statement to an equivalent if statement.

t

What is the value of the following expression? true || true && false a) false b) true

t

Analyze the following code: int x = 0; if ( x > 0); { System.out.println("x"); } a) the symbol x is always printed b) nothing is printed because x > 0 is false c) The symbol x is always printed twice d) the value of variable x is always printed

a

Which of the following operators are right-associative. A. = B. && C. + (binary +) D. % E. *

a

Suppose you write the code to display "Cannot get a driver's license" if age is less than 16 and "Can get a driver's license" if age is greater than or equal to 16. Which of the following code is correct? I: if (age < 16) System.out.println("Cannot get a driver's license"); if (age >= 16) System.out.println("Can get a driver's license"); II: if (age < 16) System.out.println("Cannot get a driver's license"); else System.out.println("Can get a driver's license"); III: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age >= 16) System.out.println("Can get a driver's license"); IV: if (age < 16) System.out.println("Cannot get a driver's license"); else if (age > 16) System.out.println("Can get a driver's license"); else if (age == 16) System.out.println("Can get a driver's license"); A. I B. III C. II D. IV

a b c d

__________ are the boolean operators. A. ^ B. > C. && D. !

a b d

Analyze the following program fragment. int x; double d = 15; switch (d) { case 1.0: x =1; case 1.5: x =2; case 2.0: x =3; } a) no errors b) the switch control variable cannot be double c) the program has a compiler error because the requirement break statement is missing in the switch statement. d) the program has a compiler error because the required default case is missing in the switch statement.

b

Suppose x=10 and y=10, what is x after evaluating the expression (y > 10) && (x-- > 10)? a) 11 b) 10 c) 9

b

The not equal comparison operator is Java is _________. a) <> b) != c) != = d) ^=

b

What is y after the following switch statement is executed? int x = 3; int y = 4; switch (x + 3) { case 6: y = 0; case 7: y = 1; default: y += 1; } A. 4 B. 2 C. 1 D. 3 E. 0

b

Suppose x=0 and y=0, what is the x after evaluating the expression (y > 0) && (1>x++)? a) -1 b) 1 c) 0

c

The "less than or equal to" comparison operator in Java is __________. A. << B. =< C. <= D. < E. !=

c

The __________ operator can be used to compare two values. a) numerical b) Boolean c) rational d) casting

c

The following code displays ___________. double temp = 50; if ( temp >= 100) System.out.println(" too hot"); else if (temp <= 40 ) System.out.println(" too cold"); else System.out.println( " just right"); a) too cold b) too hot too cold just right c) just right d) too hot

c

What is 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5? A. true B. false C. There is no guarantee that 1 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1 == 0.5 is true.

c

Suppose isPrime is a boolean variable, which of the following is the correct and best statement for testing if isPrime is true. A. if (isPrime = true) B. if (!isPrime = false) C. if (!isPrime == false) D. if (isPrime) E. if (isPrime == true)

d

int x=9; int y=8; int z=7; if(x > 9) if(y > 8) System.out.println(" x > 9 and y > 8"); else if ( z >= 7) System.out.println(" x <= 9 and z >= 7"); else System.out.println(" x <=9 and z < 7); a) x <=9 and z>+7; b) x > 9 and y > 8; c) x <=9 and z < 7; d) none

d

T or F: In a switch statement, the default case must appear last among all cases. Otherwise, it would result in a compilation error.

f

T or F: The default case must be specified in a switch statement.

f


Related study sets

CHAPTER 7: Credit cards and consumer loans

View Set

1-Network Fundamentals - Basic Question_14548700_2023_01_05_20_23

View Set

NCLEX Questions for Nursing 102 Exam #2

View Set

Math SAT Level I - Chapter 4 Ratios and Proportions

View Set

E-business Management- Ch.10 Online Content and Media

View Set

Weeks 2-6 Concepts: Poli Sci 1155 - class notes

View Set

Ch. 11 Decision Making and Relevant Information

View Set

MAR3023 Practice Exams Midterm 2

View Set

Ch. 15 Critical Thinking in Nursing Practice

View Set

Microbiology - Ch 14: An Introduction to Host Defenses and Innate Immunities

View Set