Question: The purpose of this exercise is to practice reading code and recognizing the processing patterns discussed in dealing with arrays. The following methods are hard

The purpose of this exercise is to practice reading code and recognizing the processing patterns discussed in dealing with arrays. The following methods are hard to read, because instead of using meaningful names for the variables and methods, they use names of fruit.

For each method, write one sentence that describes what the method does, without getting into the details of how it works. For each variable, identify the role it plays.

public static int banana(int[] a) {

int kiwi = 1;

int i = 0;

while (i < a.length) {

kiwi = kiwi * a[i];

i++;

}

return kiwi;

}

public static int grapefruit(int[] a, int grape) {

for (int i = 0; i < a.length; i++) {

if (a[i] == grape) {

return i;

}

}

return -1;

}

public static int pineapple(int[] a, int apple) {

int pear = 0;

for (int pine : a) {

if (pine == apple) {

pear++;

}

}

return pear;

}

Please be original in your response by not copying information off of the internet!

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!