Ask Question
30 September, 17:19

Write the definition of a method named countPos that receives a reference to a Scanner object associated with a stream of input consisting of integers only. The method reads all the integers remaining to be read in standard input and returns the number that are positive. So if the input were:

+1
Answers (1)
  1. 30 September, 20:27
    0
    static int countPos (Scanner input) {

    int count=0;

    int value;

    if (input. hasNextInt ()) {

    value=input. nextInt ();

    count=countPos (input);

    if (value>0)

    count++;

    }

    else{

    return count;

    }

    return count;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write the definition of a method named countPos that receives a reference to a Scanner object associated with a stream of input consisting ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers