Question: Write the following recursive method int count negative (int[] list, int n) that returns the number of negative integers in an integer array. 1. Base
![Write the following recursive method int count negative (int[] list, int](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f525b2d910b_00266f525b266056.jpg)
Write the following recursive method int count negative (int[] list, int n) that returns the number of negative integers in an integer array. 1. Base case n==0: return list[0]>0 ? 1:0 2. Recursive case n>0: return (list[n]>0 ? 1 : 0) + count negative (list, n-1) Use the following class to test the method public class HW2 { public static void main(String[] args) { // initial data set, add a few more members int[] data { -1, 2, -43, 14, -5}; // replace ??? with appropriate call System.out.println("Count = " + ??? ); } = public static int count negative (int[] list, int n) { int result; if (n==0) { // your code } else { // your code } return result; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
