The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Java quiz, having difficulty with working on these
Question 1 (2 points)
An array contains a group of items that are all of the same type and that are directly accessed through the use of an array index.
Question 1 options:
|
|
True |
|
|
False |
Save
Accessing areas outside of the array bounds results in:
Question 2 options:
|
|
both b and c |
|
|
both a and c |
|
|
bizarre and unexpected results |
|
|
increased memory usage |
|
|
an error |
Save
Using arrays leads to more reliable programs.
Question 3 options:
|
|
True |
|
|
False |
Save
If i and j are not the same value the following code segments are equivalent:
Question 4 options:
|
|
both b and d |
|
|
Array[ j ][ j ] and Array[ i ][ i ] |
|
|
Array[ i ][ i ] and Array[ j ][ j ] |
|
|
Array[ i ][ j ] and Array[ j ][ i ] |
|
|
Array[ i ][ j ] and Array[ i ][ j ] |
Save
Because there is random access to array items there is no time difference in using multi-dimensional arrays vs one dimensional arrays.
Question 5 options:
|
|
True |
|
|
False |
Save
How could the following code segment be better optimized?
for ( discountType = 0; discountType<typeCount; discountType++ ) {
for ( discountLevel = 0; discountLevel<levelCount; discountLevel++ ) {
rate[ discountLevel ] = rate[ discountLevel ] * discount[ discountType ];
}
}
Question 6 options:
|
|
multiply rate and discount in the outer loop |
|
|
store discountType in the outer loop for use in the inner loop |
|
|
store discountLevel in the outer loop for use in the inner loop |
|
|
compute rate in the outer loop |
Save
The optimization in the code from question #6 is because:
Question 7 options:
|
|
Accessing an array element takes longer than a accessing a non-array variable |
|
|
Storing the rate in the outer loop requires fewer math problems |
|
|
The multiplication can be done fewer times in the outside loop |
|
|
The inner loop runs more times than the inner loop |
Save
What are the missing labels from the following image?
Question 8 options:
|
|
X and y |
|
|
First and second |
|
|
Column and row |
|
|
Row and column |
Save
The following pseudo code is legal: variableType[][] b = {1, 2}, {3, 4, 5}
Question 9 options:
|
|
True |
|
|
False |
Save
A jagged array is implemented as a two-dimensional array in which each element refers to a one-dimensional array.
Question 10 options:
|
|
True |
|
|
False |
Save
What is the output for the following code:
int array[] = {10,23,45,1,78};
for(intcounter:array)
System.out.println(counter);
Question 11 options:
|
|
102345178 |
|
|
10,23,45,1,78 |
|
|
12345 |
|
|
1,2,3,4,5 |
Save
The following is the correct syntax for passing a multi-dimensional array into a function:
public void function(int[][] matrix){
}
Question 12 options:
|
|
True |
|
|
False |
Save
Describe the following code segment:
int[][] b = new int[5][];
Question 13 options:
|
|
This is a dynamic array |
|
|
This is an matrix with the columns initialized |
|
|
This is an matrix with the rows initialized |
|
|
This is a syntax error |
Save
Which is the correct code to process all the values in a 5x5 matrix:
Question 14 options:
|
|
nfor(inti=0;i<5;i++) |
|
|
for(inti=0;i<5;i++) |
|
|
for(inti=0;i<5;i++) |
|
|
for(inti=0;i<5;i++) |
Save
Which code adds a new element to a variable length String array called items?
Question 15 options:
|
|
items.add(0,”Yellow”) |
|
|
items.add(“Yellow”) |
|
|
items = new String(“Yellow”) |
|
|
items.addString(“Yellow”) |
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly