CST 8110 Quiz Answers
CST 8110 Quiz Answers
CST 8110 Quiz Answers
When a program runs on a computer, the part of the computer that carries out the instructions
is called the CPU
3. Flash drives, CDs, external disks are all examples of external storage (memory) devices.
5. A binary digit
a. is either positive or negative.
b. is zero or one.
c. requires one byte of storage.
d. is 2.
e. is none of the above.
6. A bit is
a. a metalic rod inserted into a horses mouth to control it while riding.
b. a small amount of data.
c. an alternative term for byte.
d. an electronic device used in computers.
e. a binary digit, like 0 or 1.
16. The ability of a language to let a programmer develop a program on computer system that can
be run on other systems is called portability.
17. To run a Java program from a command line, we use the java command.
18. Files containing Java code must end with what "extension"? .java.
20. Division by zero when the program is executing is an example of a run-time error.
21. The purpose of testing a program with different combinations of data is to expose run-time and
logic errors.
24. Which of the following lines contains a valid, though not necessarily accurate, comment?
a. int twoPi = 3.14159; /* holds the value of two times pi */
b. int twoPi = 2*3.14159; /* holds the value of two times pi //*
c. int twoPi = 2*3.14159; / / *holds the value of 6 //*
d. double twoPi = 2*3.14159; /* // holds the value of two time pi */ [comment] //
25. Which of the following lines does NOT consist of (a) valid, though boastful, comment(s)?
a. // /* This is a */ First Rate Program
b. //**// This is a //**// First Rate Program //**//
c. //* This is a //*// First Rate Program //*//
d. /* This is a //*// First Rate Program //*//
26. We hope you never have to encounter anything like the following expression in a program, but
consider it for a moment and indicate its value: ( /* 5 + 3 */ - 9 + 6/*8*//2 ) //*+4*/ -10
a. 3
b. -7
c. -6
d. 5
e. -8
31. Which of the following names in a program is equivalent to the name int?
a. Int
b. INT
c. All of the above
d. None of the above
33. The rules that govern the correct order and usage of the elements of a language are called the
syntax of the language
34. An error in a program that involves a violation of language rules will be detected at compile
time.
37. The character escape sequence to force the cursor to go to the next line is: \n
38. The character escape sequence to force the cursor to advance forward to the next tab setting is:
\t
39. The character escape sequence to represent a single quote is: \'
40. The character escape sequence to represent a double quote is: \"
43. Which is the best identifier for a variable to represent the amount of money your boss pays you
each month?
a. notEnough
b. wages
c. paymentAmount
d. monthlyPay
e. money
44. Of the following variable names, which is the best one for keeping track of whether a patient
has a fever or not?
a. temperature
b. feverTest
c. hasFever
d. fever
45. Of the following variable names, which is the best one for keeping track of whether an integer
might be prime or not?
a. divisible
b. isPrime
c. mightBePrime
d. number
46. A location in memory used for storing data and given a name in a computer program is called a
variable because the data in the location can be changed.
47. In Java, an argument is:
a. a logical sequence of statements proving the correctness of a program.
b. information that a method returns to its caller.
c. information provided to a method.
d. a verbal dispute.
48. Consider this code: "int v = 20; --v; System.out.println(v++);". What value is printed, what value
is v left with?
a. 20 is printed, v ends up with 19
b. 19 is printed, v ends up with 20
c. 20 is printed, v ends up with 20
d. 19 is printed, v ends up with 19
e. cannot determine what is printed, v ends up with 20
49. Consider this code: "int s = 20; int t = s++ + --s;". What are the values of s and t?
a. s is 19 and t is 38
b. s is 20 and t is 39
c. s is 19 and t is 39
d. s is 20 and t is 40
e. s is 20 and t cannot be determined
50. You need to write a loop that will repeat exactly 125 times. Which is the preferred loop
construct to use
a. while loop
b. do while loop
c. for loop
51. You need to write a loop that will keep reading and adding integers to a sum, until the sum
reaches or exceeds 21. The numbers are all less than 20 and the sum is initially 0. Which is the
preferred loop construct to use?
a. while loop
b. do while loop
c. for loop
52. You need to write a loop that reads integers and adds them to a sum as long as they are
positive. Once 0 or a negative value is read in your loop terminates. Which is the preferred loop
construct to use?
a. while loop
b. do while loop
c. for loop
53. You have a variable, n, with a non-negative value, and need to write a loop that will keep print n
blank lines. What loop construct should you use?
a. while loop
b. do while loop
c. for loop
54. An array of 1000 integers has been created. What is the largest integer that can be used as an
index to the array?
a. 1001
b. 1000
c. 999
55. Consider the declaration: int v[] = new int[1]; What is the index of the last element of this array?
a. 0
b. 1
c. 2
56. Suppose v is an array with 100 int elements. If 100 is assigned to v[100], what happens?
a. The compiler issues an error message.
b. The compiler issues a warning message.
c. An exception will be thrown when that statement is executed.
d. Another variable or array will be unexpectedly modified.