Code

int myArray[];
int nElements = 100;
myArray = new int[nElements];
for (int i=0; i < nElements; i++){
  int randomInt = (int)random(100);
  myArray[i] = randomInt;
}

int threshold = 90;
int nGreaterThanThreshold = 0;
for (int i=0; i<nElements; i++){
  int aValue = myArray[i];
  if (aValue > threshold){
    nGreaterThanThreshold++;
  }
}
println("The number of myArray values greater than " + threshold + " is " + nGreaterThanThreshold); 

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