You are on page 1of 5

Sample Quiz #1--Answers

CS 151

Sample Quiz #1Answers


1. Another term for programs is: a. Hardware b. Software c. Firmware d. Peopleware ANS: B 2. Variables are: a. Symbolic names made up by the programmer that represents locations in the

computer's RAM
b. Reserved words c. Symbolic names made up by the programmer whose values cannot be changed d. Operators that perform operations on one or more operands ANS: A 3. Byte code instructions are: a. Another name for source code b. Syntax errors c. Machine code instructions d. Read and interpreted by the JVM ANS: D 4. The purpose of validating the results of the program is: a. To create a model of the program b. To correct syntax errors c. To correct runtime errors d. To determine if the program solves the original problem ANS: D 5. Each method manipulates one or more: a. Attributes b. Other methods c. Classes d. Objects ANS: A 6. Key words are: a. The data names in your program b. Words that have a special meaning in the programming language c. Symbols or words that perform operations on one or more operands d. Words or names defined by the programmer ANS: B

ECC

Niko ulevski

Sample Quiz #1--Answers

CS 151

7. Which of the following will compile a program called ReadIt? a. java ReadIt.java b. java ReadIt.javac c. javac ReadIt.java d. javac ReadIt.javac ANS: C 8. Which of the following is not part of the programming process? a. Design b. Testing c. Debugging d. All the above are parts of the programming process ANS: D 9. If the following Java statements are executed, what will be displayed?

System.out.println("The top three winners are\n"); System.out.print("Jody, the Giant\n"); System.out.print("Buffy, the Dwarf"); System.out.println("Adelle, the Albino"); a. The top three winners are Jody, the Giant Buffy, the Dwarf Adelle, the Albino b. The top three winners are Jody, the Giant\nBuffy, the DwarfAdelle, the Albino c. The top three winners are Jody, the Giant\nBuffy, the DwarfAdelle, and the Albino d. The top three winners are Jody, the Giant Buffy, the DwarfAdelle, the Albino
ANS: D 10. Which of the following is not a primitive data type? a. short b. long c. float d. String ANS: D 11. Which of the following is valid? a. float y;

y = 54.9;
b. float y;

double z; z = 934.21; y = z; c. float w; w = 1.0f;


ECC

Niko ulevski

Sample Quiz #1--Answers

CS 151

d. double v;

v = 1.0f;
ANS: C 12. What will be displayed as a result of executing the following code?
int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

a. b. c. d.

x = 32, y = 4 x = 9, y = 52 x = 37, y = 5 x = 160, y = 80

ANS: C 13. What will be the value of z as a result of executing the following code?

int x = 5, y = 28; float z; z = (float) (y / x); a. 5.0 b. 5.6 c. 3.0 d. 5


ANS: A 14. Which of the following is not a valid comment statement? a. // comment 1 b. /* comment 2 */ c. */ comment 3 /* d. /** comment 4 */ ANS: C 15. What would be displayed as a result of the following code, assuming x has been declared an int?

x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house."); a. There are 583 hens in the hen house. b. There are 5785 hens in the hen house. c. There are x5\nhens in the hen house. d. There are 5785 hens in the hen house.
ANS: D

ECC

Niko ulevski

Sample Quiz #1--Answers

CS 151

16. To display the output on the next line, you can use the println method or use the escape sequence,

_____, in the print method. a. \n b. \r c. \t d. \b


ANS: A 17. What is the result of the following expression?

25 - 7 * 3 + 12 / 3
a. b. c. d.

6 8 10 12

ANS: B 18. What will be displayed after the following statements have been executed?

int x = 15, y = 20, z x += 12; y /= 6; z -= 14; System.out.println("x ", ", a. x = 27, y = 3.333, z = 18 b. x = 27, y = 2, z = 18 c. x = 27, y = 3, z = 18 d. x = 37, y = 14, z = 4
ANS: C

= 32;

= " + x + y = " + y + z = " +z);

19. What will be the value of z after the following statements have been executed?

int x = 4, y = 33; double z; z = (double) (y / x); a. 8.25 b. 4 c. 8 d. 8.0


ANS: D 20. What is the result of the following expression?

17 % 3 * 2 - 12 + 15
a. 7 b. 8
ECC

Niko ulevski

Sample Quiz #1--Answers

CS 151

c. 12 d. 105 ANS: A 21. Which of the following is a valid Java statement? a. String str = 'John Doe'; b. string str = 'John Doe'; c. string str = "John Doe"; d. String str = "John Doe"; ANS: D

Answers:
1 B 2 A 3 D 4 D 5 A 6 B 7 C 8 D 9 10 11 12 13 14 15 16 17 18 19 20 21 D D C C A C D A B C D A D

ECC

Niko ulevski

You might also like