Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

Students also viewed these Databases questions

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago