GoConqr has a new look! Let us know what you think.

Notes

2_Chapter 3 Test Study Guide

Terri FLetcher Introduction to Computer Programming using Java 11-12 English 1 page

Content of the notes (1)

Page 1

Chapter 3 Test Study Guide

1. The "less than or equal to" comparison operator in Java is ___E_______.

A. <

B. <=

C. =<

D. <<

E. !=

2. The equal comparison operator in Java is _C_________.

A. <>

B. !=

C. ==

D. ^=

3. What is 1 + 1 + 1 + 1 + 1 == 5? A

A. true

B. false

C. There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5 is true.

4. What is 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0? C

A. true

B. false

C. There is no guarantee that 1.0 + 1.0 + 1.0 + 1.0 + 1.0 == 5.0 is true.

5. Which of the following code displays the area of a circle if the radius is positive. A

A. if (radius != 0) System.out.println(radius * radius * 3.14159);

B. if (radius >= 0) System.out.println(radius * radius * 3.14159);

C. if (radius > 0) System.out.println(radius * radius * 3.14159);

D. if (radius <= 0) System.out.println(radius * radius * 3.14159);

6. Suppose x = 1, y = -1, and z = 1. What will be displayed by the following statement? (Please indent the statement correctly first.) C

if (x > 0)

if (y > 0)

System.out.println("x > 0 and y > 0");

else if (z > 0)

System.out.println("x < 0 and z > 0");

A. x > 0 and y > 0

B. x < 0 and z > 0

C. x < 0 and z < 0

D. none

7. What is the output of the following code? B

int x = 0;

if (x < 4) {

x = x + 1;

}

System.out.println("x is " + x); D

A. x is 0

B. x is 1

C. x is 2

D. x is 3

E. x is 4

8. The following code displays ____A_______.

double temperature = 50;

if (temperature >= 100)

System.out.println("too hot");

else if (temperature <= 40)

System.out.println("too cold");

else

System.out.println("just right");

A. too hot

B. too cold

C. just right

D. too hot too cold just right

9. Suppose income is 4001, what is the output of the following code: C

if (income > 3000) {

System.out.println("Income is greater than 3000");

}

else if (income > 4000) {

System.out.println("Income is greater than 4000");

}

A. no output

B. Income is greater than 3000

C. Income is greater than 3000 followed by Income is greater than 4000

D. Income is greater than 4000

E. Income is greater than 4000 followed by Income is greater than 3000

10. The ___D_______ method immediately terminates the program.

A. System.terminate(0);

B. System.halt(0);

C. System.exit(0);

D. System.quit(0);

E. System.stop(0);

11. 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? B

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. II

C. III

D. IV

12. 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 the best? C

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. II

C. III

D. IV

13. Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? D

A. 1 < x < 100 && x < 0

B. ((x < 100) && (x > 1)) || (x < 0)

C. ((x < 100) && (x > 1)) && (x < 0)

D. (1 > x > 100) || (x < 0)

14. Assume x = 4 and y = 5, Which of the following is true? A

A. x < 5 && y < 5

B. x < 5 || y < 5

C. x > 5 && y > 5

D. x > 5 || y > 5

15. Assume x = 4, Which of the following is true? C

A. !(x == 4)

B. x != 4

C. x == 5

D. x != 5

16. Assume x = 4 and y = 5, Which of the following is true? D

A. !(x == y)

B. x != y

C. x == y

D. x >= y

17. Which of the following is equivalent to x != y? D

A. ! (x == y)

B. x > y && x < y

C. x > y || x < y

D. x >= y || x <= y

18. Suppose x=10 and y=10. What is x after evaluating the expression (y > 10) && (x-- > 10)? B

A. 9

B. 10

C. 11

19. Suppose x=10 and y=10 what is x after evaluating the expression (y > 10) && (x++ > 10). A

A. 9

B. 10

C. 11

20. Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x-- > 10). B

A. 9

B. 10

C. 11

21. Suppose x=10 and y=10 what is x after evaluating the expression (y >= 10) || (x++ > 10). A

A. 9

B. 10

C. 11

22. Analyze the following code: D

if (x < 100) && (x > 10)

System.out.println("x is between 10 and 100");

A. The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses.

B. The statement has compile errors because (x<100) & (x > 10) must be enclosed inside parentheses and the println(?) statement must be put inside a block.

C. The statement compiles fine.

D. The statement compiles fine, but has a runtime error.

23. The order of the precedence (from high to low) of the operators binary +, *, &&, || is: C

A. &&, ||, *, +

B. *, +, &&, ||

C. *, +, ||, &&

D. ||, &&, *, +

24. What is y displayed in the following code? B

public class Test1 {

public static void main(String[] args) {

int x = 1;

int y = x = x + 1;

System.out.println("y is " + y);

}

}

A. y is 0.

B. y is 1 because x is assigned to y first.

C. y is 2 because x + 1 is assigned to x and then x is assigned to y.

D. The program has a compile error since x is redeclared in the statement int y = x = x + 1.

25. Which of the following operators are right-associative. B

A. *

B. + (binary +)

C. %

D. &&

E. =

Information

Description
11-12 Introduction to Computer Programming using Java Note on 2_Chapter 3 Test Study Guide, created by Terri FLetcher on 17/02/2016.
Created by
Terri FLetcher
Views
8
History
  • Created by Terri FLetcher · Feb 17, 2016
  • Copied by apeebles5275 · Feb 17, 2016
  • Copied by Terri FLetcher · Feb 17, 2016
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?