Lesson Set 10 - CS 1136 Lab 10 Arrays A one dimensional...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 1136 Lab 10 Arrays A one dimensional array is a data type in which a collection of places is given a name and the individual places are accessed by their position (index) within the collection. int [] numberList= new int[100]; In the above example, numberList is an array variable that contains the address of 100 integer variables. An individual integer variable within the array is accessed by giving the name of the array variable followed by its position (index). For example, numberList[0] accesses the first variable in the collection, and numberList[99] accesses the last variable in the collection. Note that the items in the collection are indexed from zero through the number in the collection minus 1. This is the reason why many programmers always begin for loops at zero. For example, the following code will assign zero to every variable in the array numberList. for (int index = 0; index < 100; index++) numberList[index] = 0; This technique can be used to initialize arrays at the beginning of the program; however, we can also initialize arrays like this: char [] charList = {‘a’, ‘b’, ‘c’, ‘d’}; We can leave out the 4 in the brackets on the previous statement, since we are explicitly telling the compiler how many elements charList contains. This can only be done when the array is declared. Out-of-bounds errors
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2012 for the course CS 1136 taught by Professor N/a during the Fall '08 term at University of Texas at Dallas, Richardson.

Page1 / 2

Lesson Set 10 - CS 1136 Lab 10 Arrays A one dimensional...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online