Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics The Exploration & Analysis Of Data

Authors: Roxy Peck, Jay L. Devore

7th Edition

0840058012, 978-0840058010

More Books

Students also viewed these Programming questions