Question: Write a public instance method named countPositive that takes a Scanner object as its only argument, and returns an int. The method's header should look
Write a public instance method named countPositive that takes a Scanner object as its only argument, and returns an int. The method's header should look like this:
public int countPositiveScanner input
Assume that the Scanner object is connected to a file that contains a series of integers one per line which the method will read. The file is already opened, and the Scanner object is ready to read the file.
The countPositive method should do the following:
Recursively count the number of positive integers in the file greater than
Return the total count of positive integers.
For example, if the file contains the following numbers:
Then, calling countPositive should return because there are two positive numbers: and
Do not use loops like for, while, or dowhile in your solution. Use only recursion.
Note: Assume the file contains at least one number.
else
returncountFromRest;
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
