Gregory M. Kapfhammer
Key Concept
Corresponding Diagram
In-Class Discussion
In-Class Activity
Details in the Textbook
An array stores a list of values
The number corresponding to each position is the index
An array of size N is indexed from 0 to N-1
Why do we start the index at the value of 0?
Ensures that the index is within the array
Why is this important to perform?
Let's avoid buffer overflow attacks!
Also, enables the detection of program defects
Can this be fully done at compile time?
What are the associated overheads?
How do we declare an array?
int[] grades;
and int grades[];
are both acceptable
Be consistent when you are implementing your programs!
What is the "Google Standard" for this?
How do we initialize an array to specific values?
int[] scores = {87, 98, 60, 80};
What method always accepts an array as a parameter?
An array as a parameter can be modified
You can change the contents of the array
You cannot make the array refer to another array
Are there other ways to give a program input?
Yes! You can input command-line arguments.
Did you ever notice that main
has a parameter?
What is the purpose of String[] args
?
What is the meaning of? ...
private int board[][] = new int[3][3];
board[0][0] + board[0][1] + board[0][2]
String[] outcome = {"O wins", "Tie", "X wins"};
What is the output of this program?
What is the purpose of this class?
What is the meaning of? ...
protected char[] encoder = new char[26];
encoder[k] = (char) ('A' + (k + rotation) % 26
for (int k=0; < msg.length; k++)
if (Character.isUpperCase(msg[k]))
msg[k] = code[j];
What is the output of this program?
clone
methodSystem.arraycopy
methodclone
in Figure 3.24clone
in Figure 3.25