2. (20 pts) a. complete the method below named positivesonly that returns the number of elements with…

2. (20 pts) a. complete the method below named positivesonly that returns the number of elements with positive values in the array nums. assume the array is filled to physical capacity. public static int positivesonly (int nums) { } b. call the method positivesonly written in part a and pass the array declared and initialized below named myarray as an argument to the method. the result of the call should be output and labeled appropriately. public static void main(string args) { int myarray = {-7, 0, -3, 5, 8}; }

2. (20 pts) a. complete the method below named positivesonly that returns the number of elements with positive values in the array nums. assume the array is filled to physical capacity. public static int positivesonly (int nums) { } b. call the method positivesonly written in part a and pass the array declared and initialized below named myarray as an argument to the method. the result of the call should be output and labeled appropriately. public static void main(string args) { int myarray = {-7, 0, -3, 5, 8}; }

Answer

Explanation:

Step1: Define the positiveOnly method

public static int positiveOnly(int[] nums) {
    int count = 0;
    for (int num : nums) {
        if (num > 0) {
            count++;
        }
    }
    return count;
}

Step2: Call the method in main

public static void main(String[] args) {
    int[] myArray = {-7, 0, -3, 5, 8};
    int result = positiveOnly(myArray);
    System.out.println("The number of positive elements is: " + result);
}

Answer:

The Java code above first defines the positiveOnly method which counts the number of positive elements in the given array. Then in the main method, it creates an array and calls the positiveOnly method, printing out the result.