U3: Arrays Flashcards
1
Q
Array: Cells
A
- Has index starting from 0 and increment by 1
- Index is reference to location of item
1
Q
Array: Storing Data
A
- Can only store data all of same type
- Ex: Integers, Strings
1
Q
Array: Names
A
- Must be done same way as variables
- Camel notation if name has +2 words
- Ex: studentMarks, cardValues
1
Q
Array: Size
A
Programmer should know and state (vertical) size of array before using
2
Q
Declaring Arrays
A
- Declare name, size and type of data stored
- Ex: int [ ] exampleName = new int [6]; for 0 to 5
3
Q
Initializing Arrays
A
int [ ] values = new int [2];
values [0] = 3;
values [1] = 71;
4
Q
Declaring and Initializing Arrays at Same Time
A
Double [ ] avg = {34.7, 54.3, 8.9}
5
Q
Storing Inputs In Array
A
- int [ ] numbers = new int [1];
- numbers[0] = keyedInput.nextInt();
6
Q
Operations on Array Number Values
A
Possible
7
Q
Outputting Array Values
A
- Can only output one value at time
- Ex:
System.out.println(values[0]);
System.out.println(values[1]);
8
Q
Element
A
Actual data stored in array cell
9
Q
Index
A
Location/index value where element located
10
Q
Bounds
A
Highest and lowest indexes (0 to [size - 1])
11
Q
i++ and iā
A
- i++: i = i + 1
- iā: i = i - 1
12
Q
Finding Odd and Even Values
A
- Odd: variable % 2 = 1
- Even: variable % 2 = 0