Lecture 19, CS 302-6, October 17
i. no 2d arrays on exam
i. Monday afternoon (not 3-4)
ii. Tuesday 12:30-2:30
iii. Wednesday afternoon
iv. Thursday 12:30-2:30, (exam 5-7)
v. Review session Tuesday, 5-7, CS 1257
i. [][] or {{,},{,}, }
i. [I][j]
ii. [row][column]
i. traversing with nested for loops
1. Note x[j] refers to an array itself if x is a 2 dimensional array
2. So, we have x.length, x[I].length
a. X.length is the number of rows in the entire array, x[I].length is the number of columns in the array stored at row i
3. Note 2d arrays can contain different numbers of rows and columns.
ii. Example TopicsChooser.java
i. Arrays
ii. Methods
iii. Stepwise Refinement, Call Stack Tracing
iv. Scanner, random, etc
v. Loops
vi. Boolean Operators
vii. Conditional Statements
viii. Data Types
i. Why arrays? They allow us to hold multiple pieces of data in one variable
ii. What is an array? List of elements
1. Each element can be referred to by an index
a. Start counting at 0
2. Size number of elements
a. .length
iii. Declaring
1. type[] name=new type[length]
a. if we do this, we initialize each value to something
i. example int[] initializes each value to 0
2. type[] name={x1, x2, ,xi-1}, i is length
3. Can be of any type: int, double, String, etc
iv. Using
1. name[index]
v. Arrays as reference
1. keep in mind variables only store one value
a. so, the variable for an array just stores a pointer to a memory location that stores the array