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

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

View Full Document Right Arrow Icon
CS125 Course Notes Lecture 20, Slide 1 Lecture 20 Multi-dimensional Arrays (Savitch 6.5)
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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.
Background image of page 4
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];
Background image of page 5

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

View Full DocumentRight Arrow Icon
Course Notes Lecture 20, Slide 6 Accessing the array • Key idea: ensure indices match the dimension you wish. • Example:
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 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 Right Arrow Icon
Ask a homework question - tutors are online