Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
|
1.
|
What is the output of the following program?
public class Test
{ public static void main(String [] args) { int
[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int value =
9; boolean foundIt = false; for(int i=0; i < a.length;
i++) { if (a[i] == value)
{
System.out.println(i); foundIt =
true; } } if
(!foundIt) System.out.println("value not
found"); } }
a. | value not found | c. | 8 | b. | -1 | d. | 9 |
|
|
|
2.
|
Which assigns the value 10 to the first array element in the studentAges
array?
a. | studentAges(1) = 10; | c. | studentAges[1] = 10; | b. | studentAges[0] = 10; | d. | studentAges[0:10]; |
|
|
|
3.
|
Which one of the following is a declaration of an int array?
a. | a [int]; | c. | integer [ ] a; | b. | int [ ]
a; | d. | [ ] int
a; |
|
|
|
4.
|
What symbol do you use next to a data type to indicate an array?
|
|
|
5.
|
Which is not a keyword used to write a loop?
|
|
|
6.
|
The array instance has an attribute named ____ that contains the number of
elements in the array.
a. | number | c. | length | b. | elementNumber | d. | count |
|
|
|
7.
|
How many elements are there in the following array?
boolean[] answers = { true, false, true, true, false };
|
|
|
8.
|
Which is not true?
a. | Java uses code blocks to group statements. | b. | The compiler
requires you to indent code. | c. | The compiler lets you extend a statement over
more than one line - no continuation character is required. | d. | None of the
above. |
|
|
|
9.
|
What is the output of the following code
segment?
int X =
10; if (X >= 10)
{
System.out.print(“ABC”);
System.out.println(“XYZ”);
}
a. | ABCXYZ | c. | ABC | b. | ABC XYZ | d. | XYZ |
|
|
|
10.
|
Which is not a Java logical operator?
|
|
|
11.
|
Which correctly assigns the character value A to variable c?
a. | assign c = 'A'; | c. | c =
'A'; | b. | c = "A"; | d. | c = A |
|
|
|
12.
|
Which one of the following is the correct declaration for a String
array?
a. | String anArrayOfStrings; | c. | string[]
anArrayOfStrings; | b. | String[]
anArrayOfStrings; | d. | anArrayOfStrings String[]; |
|
|
|
13.
|
The statement String s; does not ____.
a. | point to a String instance | c. | create a variable named
s | b. | have a null value | d. | None of the above. |
|
|
|
14.
|
What is the output of the following program?
public class ArrayDemo
{ public static void main(String[] args)
{ int[]
anArray;
anArray = new
int[10]; for
(int i = 0; i < anArray.length; i++)
{ anArray[i] =
i;
System.out.print(anArray[i] + " ");
} System.out.println();
} }
a. | 0 1 2 3 4 5 6 7 8 | c. | 1 2 3 4 5 6 7 8 9 | b. | 0 1 2 3 4 5 6 7 8
9 | d. | 0 1 2 3 4 5 6 7 8 9
10 |
|
|
|
15.
|
Which is not a valid Java identifier?
a. | 3address | c. | $amount | b. | last_name | d. | None of the
above. |
|
|
|
16.
|
To allocate space for an array, you would use ____.
a. | alloc | c. | mem | b. | new | d. | spcalloc |
|
|
|
17.
|
In the statement System.out.print.ln("Hello World Wide Web");,
the information that is contained in parentheses is called a(n) ____.
a. | method | c. | identifier | b. | text object | d. | argument |
|
|
|
18.
|
Which correctly invokes the method println?
a. | System.out.println("b = " + b); | c. | println.System.out("b = "
+ b); | b. | println System.out("b = " + b); | d. | System.out(println("b = " +
b)); |
|
|
|
19.
|
Each element of myArray has a value of
____. boolean myArray = new
boolean[100];
|
|
|
20.
|
The ____ symbol is used to determine equality.
|
|
|
21.
|
The operator that has a higher precedence than plus (+) is ____.
|
|
|
22.
|
How many rows are there in the following array declaration?
int
[ ][ ] intArray = new int[5][4];
|
|
|
23.
|
The following expression is interpreted as ____.
age
>= 18 && age <= 65
a. | (age >= 18) && (age <= 65) | c. | age >= (18 && age) <=
65 | b. | (((age >= 18) && age) <= 65) | d. | (age >= (18 && (age <=
65))) |
|
|
|
24.
|
A ____ variable uses a class name as a data type and points to an instance of
that class.
a. | complex | c. | reference | b. | pointer | d. | primitive |
|
|
|
25.
|
What is the index of 300?
int [] a = {50, 75, 100,
150, 200, 300, 450, 510, 700};
|
|
|
26.
|
The following expression will be interpreted as ____.
a < b | | c >= d && e == f
a. | (a < b | | c >= d) && (e == f) | c. | (a < (b | | c) >= d)
&& (e == f) | b. | (a < b) | | ((c >= d) && (e ==
f)) | d. | (a < b) | | (c >=
d) && (e == f) |
|
|
|
27.
|
The limit on the number of dimensions in a Java array is ____.
a. | five | c. | ten | b. | eight | d. | None of the
above. |
|
|
|
28.
|
The statement 11%2 returns the value ____.
|
|
|
29.
|
Which data type does not contain numeric data without decimals?
a. | short | c. | int | b. | long | d. | double |
|
|
|
30.
|
What is the output of the following program?
public class Test
{ public static void main(String [] args) { int[]
a = {2, 4, 6, 8, 10, 12, 14}; for(int i = 0; i < a.length; i++)
{ if (i > 5)
a[i] *= 2; } printArray(a);
}
public static void printArray(int [] a) { for(int
i=0; i < a.length; i++) { System.out.print(a[i] +
" "); } } }
a. | 2 4 6 8 10 24 28 | c. | 2 4 6 8
20 24 28 | b. | 2 4 6 8 10
12 28 | d. | 2 4
6 8 10 12 14 |
|
|
|
31.
|
____ loops are post-test.
a. | do | c. | for | b. | while | d. | All of the
above. |
|
|
|
32.
|
Which of the following operators has the highest precedence?
|
|
|
33.
|
Which is the correct declaration for an array of floats?
a. | [] float anArrayOfFloats; | c. | float[]
anArrayOfFloats; | b. | anArrayOfFloats float[]; | d. | float
anArrayOfFloats; |
|
|
|
34.
|
The output of the following program is ____.
public class Test
{ public static void main(String [] args) { int[]
a = new int[7]; for(int i=0; i < 5; i++)
{ a[i] = i % 2;
} printArray(a); }
public static void printArray(int
[] a) { for(int i=0; i < a.length; i++)
{ System.out.print(a[i] + "
"); } } }
a. | 0 1 0 1 0 1 1 | c. | 1 0 1 0
0 0 0 | b. | 0 1 0 1 0 0
0 | d. | 0 1 0
1 0 1 1 |
|
|
|
35.
|
____ delineates a block of code.
|
|
|
36.
|
!(expr1 && expr2) is equivalent to ____.
a. | !(expr1) && !(expr2) | c. | !(expr1) | |
expr2 | b. | expr1 | | expr2 | d. | !(expr1) | | !(expr2) |
|
|
|
37.
|
Each element of myArray has a value of ____.
int [] myArray = new int[10];
|
|
|
38.
|
What is the length of the following array?
int[] a = {2, 4, 6, 8, 10};
|
|
|
39.
|
The output of the following program is ____.
public class Test
{ public static void main(String [] args) { String
[] a = {"One", "Two", "Three", "Four",
"Five"}; for(int i = 0; i < a.length; i++)
{ if
(a[i].equals("Three"))
System.out.println(i); } } }
|
|
|
40.
|
Which operator will negate the result of a Boolean expression?
|
|
|
41.
|
Assume that two integer variables, a and b, have values of 15 and 2
respectively. What is the result of a / b?
a. | 7 | c. | An error will result. | b. | 8 | d. | 7.5 |
|
|
|
42.
|
The following is an example of a(n) ____.
double
[ ][ ] myArray = new double[2][5];
a. | three-dimensional array | c. | one-dimensional
array | b. | two-dimensional array | d. | five-dimensional array |
|
|
|
43.
|
What is the output of the following program?
public class Test
{ public static void main(String[] args) { String
[] a = {"This", "is", "a",
"test"}; for (int i = 0; i < a.length; i++)
{ if (a[i].length() >
2)
System.out.print(a[i] + " "); }
} }
a. | this test | c. | This is | b. | This test | d. | This is a |
|
|
|
44.
|
Which statement reserves enough computer memory for 7 Employee
objects?
a. | Employee[ ] emp = new Employee[7]; | c. | Employee[7] emp = new
Employee; | b. | Employee[] emp = new Employee; | d. | Employee emp = new
Employee[7]; |
|
Completion Complete each
statement.
|
|
|
45.
|
In Java, the equal sign (=) is called the ____________________ operator.
|
|
|
46.
|
If the variable i has a value of 7, ++i returns a value of
____________________.
|
|
|
47.
|
To write the statement total = total + 5; using the assignment operator
together with the arithmetic operator you should use ____________________.
|
|
|
48.
|
The single line of code to declare a four-element array of integer elements
called studentAges is ____________________.
|
|
|
49.
|
The concatenation operator is the ____________________.
|
|
|
50.
|
The Java ____________________ statement evaluates an expression and then
executes one block of code if the expression is true and another code block if the expression is
false.
|
|
|
51.
|
You can temporarily change the data type of the value contained in a variable
using a(n) ____________________.
|
|
|
52.
|
True or false values are also known as ____________________ values.
|
|
|
53.
|
The keyword final in front of a variable indicates that the variable is
a(n) ____________________.
|
|
|
54.
|
All array elements must have the same ____________________.
|
|
|
55.
|
The ____________________ field contains the number of elements in an
array.
|
|
|
|
|
|
56.
|
Figure 2-11 is an example of a(n) ____________________ statement.
|
Matching
|
|
|
Match each item with a statement below. a. | pass by reference | f. | pass by
value | b. | multidimensional array | g. | one-dimensional array | c. | element | h. | parallel array | d. | two-dimensional
array | i. | sorting | e. | subscript |
|
|
|
57.
|
Process of passing items to a method in which the receiving method receives the
actual memory address of the item.
|
|
|
58.
|
Array with the same number of elements as another, and for which the values in
corresponding elements are related.
|
|
|
59.
|
An array that may have more than two dimensions.
|
|
|
60.
|
An array that you can picture as a column of values,and whose elements you can
access using a single subscript.
|
|
|
61.
|
Array that mathematicians often call a matrix or a table.
|
|
|
62.
|
Process of arranging a series of objects in some logical order.
|
|
|
63.
|
Process of passing items to a method where a copy is made and used within the
receiving method.
|
|
|
64.
|
One of an array’s variables.
|
|
|
65.
|
An integer contained within square brackets that indicates one of an
array’s variables.
|
True/False Indicate whether the
statement is true or false.
|
|
|
66.
|
In Java, each source code file actually defines a class.
|
|
|
67.
|
Java includes the keyword end if to indicate the end of an if-else
statement.
|
|
|
68.
|
You can declare arrays that hold elements of any type.
|
|
|
69.
|
Array subscripts may have floating-point values.
|
|
|
70.
|
Each row of a two-dimensional array must have the same length.
|
|
|
71.
|
The following assigns 14 to the first element of
someNumbers.
someNumbers[1][1] = 14;
|
|
|
72.
|
Java is not case sensitive.
|
|
|
73.
|
The statement j = ++i; is the same as the statement j =
i++;.
|
|
|
74.
|
A reference variable contains data.
|
|
|
75.
|
The statement int testScoreTable[][] = new int
[5][4]; declares an array with five columns and four rows.
|
|
|
76.
|
Java uses <> to mean not equal to.
|
Modified True/False Indicate
whether the statement is true or false. If false, change the identified word or phrase to make the
statement true.
|
|
|
77.
|
A(n) pre-test loop tests the terminating condition at the beginning of
the loop. _________________________
|
|
|
78.
|
You can access the individual elements of the array by writing the array
reference variable followed by the index value of the element enclosed in brackets.
_________________________
|
|
|
79.
|
A string literal uses single quotes. _________________________
|
|
|
80.
|
If a method is public, it means that any other program can invoke this
method. _________________________
|
|
|
81.
|
You should use a(n) do loop when you want to force the execution of the
statements in the loop body at least once. _________________________
|
|
|
82.
|
The Arithmetic class has methods to accomplish exponentiation, rounding,
and numerous other tasks. _________________________
|
|
|
83.
|
Int, short, and float are all considered primitive data types.
_________________________
|