Filters
Question type

Study Flashcards

Which set of statements totals the values in two-dimensional int array items?


A) int total = 0;
For ( int subItems : items )
For ( int item : subItems )
Total += item;
B) int total = 0;
For ( int item: int[] subItems : items )
Total += item;
C) int total = 0;
For ( int[] subItems : items )
For ( int item : items )
Total += item;
D) int total = 0;
For ( int[] subItems : items )
For ( int item : subItems )
Total += item;

Correct Answer

verifed

verified

Invalid possibilities for array indices include .


A) Positive integers.
B) Negative integers.
C) Zero.
D) None of the above.

Correct Answer

verifed

verified

In array items,which expression below accesses the value at row 3 and column 4?


A) items[ 3 ].[ 4 ].
B) items[ 3[ 4 ] ].
C) items[ 3 ][ 4 ].
D) items[ 3,4 ].

Correct Answer

verifed

verified

Which expression adds 1 to the element of array arrayName at index i?


A) ++arrayName[ i ].
B) arrayName++[ i ].
C) arrayName[ i++ ].
D) None of the above.

Correct Answer

verifed

verified

Consider the array: s[ 0 ] = 7 S[ 1 ] = 0 S[ 2 ] = -12 S[ 3 ] = 9 S[ 4 ] = 10 S[ 5 ] = 3 S[ 6 ] = 6 The value of s[ s[ 6 ] - s[ 5 ] ] is:


A) 0.
B) 3.
C) 9.
D) 0

Correct Answer

verifed

verified

Consider the code segment below.Which of the following statements is false? int[] g; G = new int[ 23 ];


A) The first statement declares an array reference.
B) The second statement creates the array.
C) g is a reference to an array of integers.
D) The value of g[ 3 ] is -1.

Correct Answer

verifed

verified

An argument type followed by a(n) in a method's parameter list indicates that the method receives a variable number of arguments of that particular type.


A) square brackets ([]) .
B) ellipsis (…) .
C) varargs keyword.
D) All of the above are acceptable to indicate a variable number of arguments.

Correct Answer

verifed

verified

Consider array items,which contains the values 0,2,4,6 and 8.If method changeArray is called with the method call changeArray( items,items[ 2 ] ) ,what values are stored in items after the method has finished executing? public static void changeArray( int[] passedArray,int value ) { PassedArray[ value ] = 12; Value = 5; } // end method changeArray


A) 0,2,5,6,12.
B) 0,2,12,6,8.
C) 0,2,4,6,5.
D) 0,2,4,6,12.

Correct Answer

verifed

verified

Which statement correctly passes the array items to method takeArray? Array items contains 10 elements.


A) takeArray( items[] ) .
B) takeArray( items ) .
C) takeArray( items[ 9 ] ) .
D) Arrays cannot be passed to methods-each item must be sent to the method separately.

Correct Answer

verifed

verified

Which of the following initializer lists would correctly set the elements of array n?


A) int[] n = { 1,2,3,4,5 };.
B) array n[ int ] = { 1,2,3,4,5 };.
C) int n[ 5 ] = { 1;2;3;4;5 };.
D) int n = new int( 1,2,3,4,5 ) ;.

Correct Answer

verifed

verified

A programmer must do the following before using an array:


A) declare then reference the array.
B) create then declare the array.
C) create then reference the array.
D) declare then create the array.

Correct Answer

verifed

verified

Attempting to access an array element out of the bounds of an array,causes a(n) .


A) ArrayOutOfBoundsException.
B) ArrayElementOutOfBoundsException.
C) ArrayIndexOutOfBoundsException.
D) ArrayException.

Correct Answer

verifed

verified

Which of the following tasks cannot be performed using an enhanced for loop?


A) Calculating the product of all the values in an array.
B) Displaying all even element values in an array.
C) Comparing the elements in an array to a specific value.
D) Incrementing the value stored in each element of the array.

Correct Answer

verifed

verified

Class Arrays provides method __________ for comparing arrays.


A) compare.
B) compares.
C) equal.
D) equals.

Correct Answer

verifed

verified

For the array in the previous question,what is the value returned by items[ 1 ][ 0 ]?


A) 4.
B) 8.
C) 12.
D) 6.

Correct Answer

verifed

verified

Which of the following will not produce a compiler error?


A) Changing the value of a constant after it is declared.
B) Changing the value at a given index of an array after it is created.
C) Using a final variable before it is initialized.
D) All of the above will produce compiler errors.

Correct Answer

verifed

verified

An array with m rows and n columns is not: a) An m-by-n array. b) An n-by-m array. c) A two-dimensional array. d) A dual-transcripted array.


A) A and C.
B) A and D.
C) B and D.
D) B and C.

Correct Answer

verifed

verified

Class Arrays methods sort,binarySearch,equals and fill are overloaded for primitive-type arrays and Object arrays.In addition,methods __________ and __________ are overloaded with generic versions.


A) sort,binarySearch.
B) sort,fill.
C) binarySearch,equals.
D) binarySearch,fill.

Correct Answer

verifed

verified

Which set of statements totals the items in each row of two-dimensional array items,and displays each total?


A) int total = 0;
For ( int row = 0;row < items.length;row++ )
{
Total = 0;
For ( int column = 0;column < a[ row ].length;column++ )
Total += a[ row ][ column ];
System.out.printf( "%d\n",total ) ;
}
B) int total = 0;
For ( int row = 0;row < items.length;row++ )
{
For ( int column = 0;column < a[ row ].length;column++ )
Total += a[ row ][ column ];
System.out.printf( "%d\n",total ) ;
}
C) int total = 0;
For ( int row = 0;row < items.length;row++ )
{
For ( int column = 0;column < a[ column ].length;column++ )
Total += a[ row ][ column ];
System.out.printf( "%d\n",total ) ;
}
D) int total = 0;
For ( int row = 0;row < items.length;row++ )
{
Total = 0;
For ( int column = 0;column < a[ column ].length;column++ )
Total += a[ row ][ column ];
System.out.printf( "%d\n",total ) ;
}

Correct Answer

verifed

verified

The preferred way to traverse a two-dimensional array is to use .


A) a do while statement.
B) a for statement.
C) two nested for statements.
D) three nested for statements.

Correct Answer

verifed

verified

Showing 21 - 40 of 41

Related Exams

Show Answer