Code
// Below is some code which fills an array (called myArray)
// with 100 random integers between 0 and 100.
//
// Write some code which uses a while{} loop to search through
// this array, starting from the lowest index (0), and
// which reports the index of the first value stored in the array
// which is greater than or equal to 96.
// In other words: report the lowest-numbered index in the array
// which stores a number greater than or equal to 96.
// You may not modify the code below; assume your code follows it.
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 number= 0;
while (myArray[number]<96){
number++;
}
println (" The "+ number + " number in the array was greater than or equal to 96 and that value was " + myArray[number]);
0504 - Array Search: Using while{}
Statement:
// Below is some code which fills an array (called myArray)
// with 100 random integers between 0 and 100.
//
// Write some code which uses a while{} loop to search through
// this array, starting from the lowest index (0), and
// which reports the index of the first value stored in the array
// which is greater than or equal to 96.
// In other words: report the lowest-numbered index in the array
// which stores a number greater than or equal to 96.
// You may not modify the code below; assume your code follows it.
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