Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started