9.1.1. Arrays-WE1-P1¶
Subgoals for Evaluating Arrays
Set up array from 0 to size-1
Evaluate data type of statements against array
Trace statements, updating slots as you go
Remember assignment subgoals
Arrays-WE1-P1
Q1: Assume the following declarations:
String [] alpha;
alpha = new String[4];
Evaluate these statements:
alpha[0] = "apple";
alpha[1] = "Banana";
alpha[2] = alpha[0].substring(2);
alpha[3] = alpha[alpha[1].indexOf('n')];
Give the contents of array alpha
after the execution of the above statements:
alpha[0] = “”
alpha[1] = “”
alpha[2] = “”
alpha[3] = “”
Q2: Assume the following declarations:
int [] beta;
beta = new int[3];
Evaluate these statements:
beta[1] = 22;
beta[0] = beta[1] - 11;
beta[2] = beta[0] + beta[1];
Give the contents of array alpha
after the execution of the above statements:
beta[0] = “”
beta[1] = “”
beta[2] = “”
- double [] gamma = new double[5];
- gamma[0] = 14;
- gamma[1] = gamma[0];
- gamma[gamma[0]] = 42;
- gamma[5] = 22;
Q3: Which line produces the first compiler error?
You have attempted of activities on this page