Arrays (Java/Turing)
CPT Girls
What are we covering?
When to Use Arrays
What is an array
What is an array
What is an array
Example of Java/Turing number indexes
Example of Turing character indexes
Indices | 0 | 1 | 2 | 3 | 4 |
Elements | “CPT!” | “is!” | “the!” | “coolest!” | “club!” |
Indices | A | B | C | D | E |
Elements | “CPT!” | “is!” | “the!” | “coolest!” | “club!” |
Syntax
| Turing | Java |
Initialization | var [arrayName]: array [start index] .. [stop index] of [data type] | int [] myArray = new int [5] |
Assignment | my_array(0) := 17 | myArray[0] = 17 |
Comparison | if my_array(0) = 17 then | if (myArray[0] == 17) |
Index number
Index number
Helpful commands for arrays (Turing)
Helpful commands for arrays (Java)
Extending - Parallel Arrays
Indices | 0 | 1 | 2 | 3 |
names | Jaclyn | Yuan | Hannah | Tina |
heights | 149 | 169 | 164 | 172 |
Example problems