![]() |
Working With Arrays
Arrays in Java are similar to C++ in their syntax, but are first-class objects with better security and more features. This Magercise shows some examples of array use. Each of the tasks is intended to be an incrementental extension of the previous. After typing them into the scrapbook, execute them to examine their behavior. Note that you may use the VisualAge Inspector to inspect the arrays. Additionally, you should know that some array operations can raise exceptions if errors occur, such as referencing an array past its boundary. There will be several Magercises later that cover exceptions in detail, but if you have the time, you may want to intentionally raise some to see what happens when they are not caught. Arrays are discussed in detail in the course notes. Tasks
Perform the following tasks:
Extend the example further by creating a new array, and
initializing it with the contents of the colors array. Use either a
for loop, as in C++, or System.arraycopy. To use
arraycopy, refer to the API for
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |