Question: public static int oddOrPos (int[] x) { // Effects: if x is null throw NullPointerException // else return the number of elements in x that

public static int oddOrPos (int[] x)

{

// Effects: if x is null throw NullPointerException

// else return the number of elements in x that

// are either odd or positive (or both)

int count = 0;

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

{

if (x[i]%2 == 1 || x[i] > 0)

{

count++;

}

}

return count;

}

Write test case as: Test case

Input, x:

Expected output value of count:

Actual output of count:

Answer questions below. When you write a test case, write it in terms of input, expected output and actual output.

Explain what is wrong with the given code. Describe the fault precisely by referring to the line with the fault

If possible, give a test case that does not execute the fault. Explain it. If not, briefly explain why not.

If possible, give a test case that executes the fault, but does not result in a failure. Explain it. If not, briefly explain why not.

Give a test case that executes the fault and results in a failure. Explain it.

Rewrite the code with the fault fixed.

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!