06.01 Virtual Lecture Notes (Part 1) : String Array Basics
06.01 Virtual Lecture Notes (Part 1) : String Array Basics
Run the program and observe the output. Answer the following questions and make the suggested
modifications. Some changes may cause errors, so restore statements to their original form before
moving on to another question.
What value does each index position contain before information is assigned to it?
What happens if you change 10 to 9 in the array declaration? (Change it back afterwards.)
What happens if you change <= to just < ? (Change it back afterwards.)
What happens if you change 0 to 1 and 9 to 10?
What statements would you change to increase the size of the array to 100 and print the
value of each position?
What could you change to print only the odd numbered index positions?
What is the meaning of an IndexOutOfBoundsException and how can it be fixed?
Once an array is declared and initialized, there are four ways to assign information to each index
position, three of which you already know from writing assignment statements in other programs.
In lesson 06.00, you made a list of 10 things that are important to you. Modify this
program to print your list, instead of the names of the Seven Dwarfs.
Add some additional names to the text file with a text editor. What happens when you
run the program? Can you fix the problem?
Determine the size of the array with the length property of arrays.
Wrap Up
Declaring, initializing, and assigning values to arrays are fundamental programming skills. Be sure
that you understand how to do each before attempting to write any of the programs in this module.
Array index positions are numbered starting at 0, which is often the source of errors. In addition,
depending on the specific circumstances, it may be necessary to use < instead of <= to establish a
loops terminating condition.