Question: Write a method called rainfall() that takes a Scanner as a parameter, representing an input source. The input source contains data representing rainfall amounts
Write a method called rainfall() that takes a Scanner as a parameter, representing an input source. The input source contains data representing rainfall amounts on different days of the week. Each amount is represented as a positive integer, and the end of the list of numbers is represented by a negative number, which signals the end of useful input. Write your method so that it continually reads numbers from the input scanner, and then computes and returns the average of the positive numbers. The method should return zero if there are no positive integers provided. You may not use any container (array, list, etc.) in your answer. (Hint: recall that the Scanner class provides hasNextInt () and nextInt () methods for dealing with integer input values). Examples: rainfall (input ("1 2 3 -1")) -> 2 rainfall (input("3 4 -10")) -> 3.5 rainfall (input("1 2 3 -1 ")) -> 2 1 public double rainfall (Scanner input) 2 { 3 4} 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
