Question: public class CountPositive { / * * * Counts positive elements in array * * @param x array to search * @return number of positive
public class CountPositive
Counts positive elements in array
@param x array to search
@return number of positive elements in x
@throws NullPointerException if x is null
public static int countPositive int x
int count ;
for int i; i xlength; i
if xi
count;
return count;
test: x
Expected
public static void main String argv
Driver method for countPositive
Read an array from standard input, call countPositive
int inArr new int argvlength;
if argvlength
System.out.println Usage: java CountPositive vvv;
return;
for int i ; i argv.length; i
try
inArr i Integer.parseInt argvi;
catch NumberFormatException e
System.out.println Entry must be a integer, using ;
inArr i;
System.out.println Number of positive numbers is: countPositive inArr;
a Count the positive numbers.
Test the following set of values
test: x
Expected result is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
