Class 25 - Arrays and Lists in Java 1 Goals for today n n...

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

View Full Document Right Arrow Icon
Arrays and Lists in Java 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Goals for today n Revisit I/O n Understand Java’s array data structure 2 MGMT 29000-002
Background image of page 2
Arrays and Lists in Java n Features common to arrays and lists ¨ Used to define variables that store groups of items ¨ Provide access to a given item using an index n Differences between arrays and lists ¨ Array’s size is fixed at runtime, a list’s size can change ¨ Array stores items using less memory than a list ¨ Array provides direct item access faster than a list MGMT 29000-002 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Introductory Example: Air Pollution Reporting n Review of AirPollutionIndex.java ¨ Read air pollution level readings from five points ¨ Compute and display the average reading (the index) n Additional requirements of the enhanced program ¨ Display the five readings used to compute the average n High-level algorithm for AirPollutionReport ¨ Build an array named readings with length = 5 ¨ Read the air pollution readings into readings ¨ Compute and display average of values in readings ¨ Display the individual values in readings MGMT 29000-002 4
Background image of page 4
Introductory Example: Air Pollution Reporting (continued) MGMT 29000-002 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Java Arrays n General pattern for defining (declaring) an array ¨ Item[] anArray = new Item[N]; n Item : specifies the items type n Brackets tell compiler that anArray is an array handle n new operator: allocates memory for the array n N : an integer that specifies the array length (size) n An example of an array definition: double[] readings = new double [NUM_READINGS]; ¨ NUM_READINGS is an integer constant = 5 ¨ readings is a handle to a 5 unit double type array MGMT 29000-002 6
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/04/2012 for the course MGMT 290 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 26

Class 25 - Arrays and Lists in Java 1 Goals for today n n...

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

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