9.10.1. Arrays-WE8-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-WE8-P1
- {20, 30, 40, 50, 60, 70, 70}
- {20, 30, 40, 50, 60, 70, 10}
- {10, 20, 30, 40, 50, 60, 70}
- {10, 10, 20, 30, 40, 50, 60}
- {70, 10, 10, 10, 10, 10, 10}
Q45: What are the contents of array alpha after this code has been executed?
int [] alpha = {10, 20, 30, 40, 50, 60, 70};
int start = alpha[alpha.length-1];
for (int i = 1; i < alpha.length; i++) {
alpha[i] = alpha[i-1];
}
alpha[0] = start;
- {20, 30, 40, 50, 60, 70, 70}
- {20, 30, 40, 50, 60, 70, 10}
- {10, 20, 30, 40, 50, 60, 70}
- {10, 10, 20, 30, 40, 50, 60}
- {70, 10, 20, 30, 40, 50, 60}
Q46: What are the contents of array beta after this code has been executed?
int [] beta = {10, 20, 30, 40, 50, 60, 70};
for (int i = 1; i < beta.length; i++) {
beta[i] = beta[i-1])
}
- {20, 30, 40, 50, 60, 70, 70}
- {20, 30, 40, 50, 60, 70, 10}
- {10, 20, 30, 40, 50, 60, 70}
- {10, 10, 20, 30, 40, 50, 60}
- IndexOutOfBounds Exception
Q47: What are the contents of array gamma after this code has been executed?
int [] gamma = {10, 20, 30, 40, 50, 60, 70};
for (int i = 0; i < gamma.length; i++) {
gamma[i] = gamma[i+1])
}
You have attempted of activities on this page