Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3. Below are four faulty programs. Each includes a test case that results in fail- ure. Answer the following questions about each program public static
3. Below are four faulty programs. Each includes a test case that results in fail- ure. Answer the following questions about each program public static int lastzero (int[] x f public int findLast (int[] x, int y) Effects: If x null throw NullPointerException Effects: if x null throw NullPointerException else return the index of the last element else return the index of the LAST 0 in x. in x that equals y Return -1 if 0 does not occur in x If no such element exists, return -1 for (int i x length-1; i 0; i--) for (int i 0; i x.length; i++) if (x[i] 2- y) if (x 0) return i return i -1 return -1; return. test: x 2, 3, 51; y 2 test: x 10, 1, 01 Expected 0 Expected 2 public int countPositive (int[J x) public static int oddorPos(int[] x) H /Effects: If x null throw NullPointerException Effects: if x null throw NullPointerException. else return the number of else return the number of elements in x that positive elements in x are either odd or positive (or both) int count 0 int count 0 for (int i 0; i
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