Question: the incorrect value 99 was found in variable i (should be 30) Your Code ( with color highlights added ): for (int j = 0;

the incorrect value 99 was found in variable i (should be 30) Your Code ( with color highlights added ): for (int j = 0; j < arraydata.lenght ; j++ ){ if (arraydata[j]==targetvar){ i = j + 1; } } The Instructions: Exercise 6.1 : O(N) Loop A classic O(N) algorithm is linear search, where every item is looked at until the target is found Write a 'for' loop to search the array of integers arraydata, use the variable i and the .length property to control the loop Use an 'if' statement to find a match for the value in the variable targetvar When the loop terminates i MUST contain the number of comparisons to find the value That number must be +1 of the slot the item was found in, if the item was found in slot zero, it took one comparison to find it Do not declare i or initialize arraydata or targetvar it will be done for you. Write only a loop with an if inside and remember when the value was found in slot 3 it took 3+1 or 4 comparisons to find it

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!