Manipulations �&�Looping Through Arrays
Lessons 8.2 & 8.3
Simple Array Manipulations
int [ ] arrayName = new int [100];
Range Bound Errors
Range Bound Errors
ArrayIndexOutOfBoundsException
Looping Through Arrays
Looping Through Arrays
Looping Through Arrays
int sum;
sum = 0;
for (int i = 0; i < 500; i++) {
sum += abc[ i ];
}
Looping Through Arrays
int x = 3, count = 0;
for (int i = 0; i < 500; i++) {
if (abc[ i ] == x) {
count ++;
}
}
Looping Through Arrays
int x = 3;
boolean found = false;
for (int i = 0; i < 500; i++) {
if (abc[ i ] == x) {
found = true;
break;
}
}
if (found) {
System.out.println (“Found”);
} else {
System.out.println (“Not Found”);
}
Looping Through Arrays
int x, location = -1;
for (int i = 0; i < 500; i++) {
if (abc[ i ] == x) {
location = i;
break;
}