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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started