lec20 - Lecture 20 Multi-dimensional Arrays (Savitch 6.5)...

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

CS125 Course Notes Lecture 20, Slide 1 Lecture 20 Multi-dimensional Arrays (Savitch 6.5)

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

View Full Document
CS125 Course Notes Lecture 20, Slide 2 Motivation • So far, our arrays have been one-dimensional: int[] mark = new int[100]; • Sometimes it may make sense to store information in more than one dimension. 99 2 1 0 49 13 99 75 mark
CS125 Course Notes Lecture 20, Slide 3 Motivation continued • Examples: – Periodic table of elements – Prices of flights between cities – Matrix of numbers – All assignment grades for all students in a course.

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

View Full Document
CS125 Course Notes Lecture 20, Slide 4 Two-dimensional arrays • Tables (or tabular data) map nicely to two- dimensional arrays. • Later, we will see how to generalize to any (fixed) number of dimensions.
CS125 Course Notes Lecture 20, Slide 5 Declaring a 2D array • Syntax: Type [][] ArrayName = new Type [ Length_1 ][ Length_2 ]; • Example: int[][] myArray = new int[3][5];

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

View Full Document
Course Notes Lecture 20, Slide 6 Accessing the array • Key idea: ensure indices match the dimension you wish. • Example:
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 20

lec20 - Lecture 20 Multi-dimensional Arrays (Savitch 6.5)...

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

View Full Document
Ask a homework question - tutors are online