{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter6_Arrays - Chapter 6 Arrays Objectives After...

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

View Full Document Right Arrow Icon
Chapter 6: Arrays
Background image of page 1

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

View Full Document Right Arrow Icon
Objectives After studying this chapter, Stdent should be able to Manipulate a collection of data values, using an array. Declare and use an array of primitive data types in writing a program. Declare and use an array of objects in writing a program Define a method that accepts an array as its parameter and a method that returns an array Describe how a two-dimensional array is implemented as an array of arrays
Background image of page 2
11/2/2008 Page 3 Array Basics An array is a collection of data values. If your program needs to deal with 100 integers, 500 Account objects, 365 real numbers, etc., you will use an array. In Java, an array is an indexed collection of data values of the same type.
Background image of page 3

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

View Full Document Right Arrow Icon
11/2/2008 Page 4 Arrays of Primitive Data Types Array Declaration <data type> [ ] <variable> //variation 1 <data type> <variable> [ ] //variation 2 Array Creation <variable> = new <data type> [ <size> ] Example double [ ] rainfall; rainfall = new double [ 12 ] ; Variation 1 double rainfall [ ] ; rainfall = new double [ 12 ] ; Variation 2 An array is like an object!
Background image of page 4
11/2/2008 Page 5 Accessing Individual Elements Individual elements in an array accessed with the indexed expression. double [] rainfall = new double [ 12 ] ; The index of the first position in an array is 0 . rainfall 0 1 2 3 4 5 6 7 8 9 10 11 rainfall[2] This indexed expression refers to the element at position #2 This indexed expression refers to the element at position #2
Background image of page 5

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

View Full Document Right Arrow Icon