Question: Consider the following method, which is intended to return the greatest absolute difference between any pair of corresponding elements in the int arrays pred and

Consider the following method, which is intended to return the greatest absolute difference between any pair of corresponding elements in the int arrays pred and act.
/** Precondition: pred and act have the same non-zero length. */
public static int diff(int[] pred, int[] act)
{
int num = Integer.MIN_VALUE;
for (int i =0; i < pred.length; i++)
{
/* missing code */
}
return num;
}
Which of the following code segments can be used to replace /* missing code */ so that diff will work as intended?
Responses
if (pred[i]< act[i])
{
num = act[i]- pred[i];
}
if (pred[i]< act[i]){ num = act[i]- pred[i]; }
if (pred[i]> act[i])
{
num = pred[i]- act[i];
}
if (pred[i]> act[i]){ num = pred[i]- act[i]; }
if (pred[i]- act[i]> num)
{
num = pred[i]- act[i];
}
if (pred[i]- act[i]> num){ num = pred[i]- act[i]; }
if (Math.abs(pred[i]- act[i])< num)
{
num = Math.abs(pred[i]- act[i]);
}
if (Math.abs(pred[i]- act[i])< num){ num = Math.abs(pred[i]- act[i]); }
if (Math.abs(pred[i]- act[i])> num)
{
num = Math.abs(pred[i]- act[i]);
}

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!