Array Operation Exercise
This is an exercise about array operations such as array declaration,
construction, initialization and high-performance copy.
Download files: ArrayOperation.java
Areas: Intro to arrays.
Download files: ArrayOperation.java
Areas: Intro to arrays.
|
|
ArrayOperation.java |
|
View full source |
| Question 1 |
| Does it make any difference if we replace line 4: int source[]= new int[6]; with int source[6];? |
| Question 2 |
| Can we replace int source[]= new int[6]; with int source[]; because we will initialize the array elements in the for-loop? |
| Question 3 |
| In the source array which is declared and constructed in int source[] = new int[6];, is source[6] a valid array element? |
| Question 4 |
| In int destination[]={10,9,8,7,6,5,4,3,2,1};, the destination array is declared, constructed and initialized. If we would like to achieve the same effect using a for-loop, what would the code look like? |
| Question 5 |
| What does the following line of code do? System.arraycopy(source,0,destination,0,source.length) |
| Question 6 |
| Can we to achieve the same effect as System.arraycopy(source,0,destination,0,source.length) using a for-loop? What would the code look like? |
| Question 7 |
| Please list the values of the destination array elements after the call to the arraycopy method. |
