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 countPositive(Scanner 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 0).
Return the total count of positive integers.
For example, if the file contains the following numbers:
5
-9
7
0
Then, calling countPositive should return 2, because there are two positive numbers: 5 and 7.
Do not use loops (like for, while, or do-while) in your solution. Use only recursion.
Note: Assume the file contains at least one number.
16
17
18
19
20
}else{
returncountFromRest;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!