Code
int counter = 0;
int myArray[];
int nElements = 100;
myArray = new int[nElements];
for (int i=0; i < nElements; i++){
int randomInt = (int)random(100);
myArray[i] = randomInt;
if (myArray[i] > 90){
println ("Elements > than 90: " + myArray[i]);
counter++;
}
}
println (counter);
0502 - Arrays: Conditional testing on Array Elements
Statement:
// Below is some code which fills an array (called myArray)
// with 100 random integers between 0 and 100.
// Write some code which counts the number of values
// stored in this array which are greater than 90.
// You may not modify the code below; assume your code follows it.
// Report the counted total with a println().
int myArray[];
int nElements = 100;
myArray = new int[nElements];
for (int i=0; i < nElements; i++){
int randomInt = (int)random(100);
myArray[i] = randomInt;
}
hide statement