Problem

Accumulating Totals in a Loop In this exercise, you use what you have learned about us...

Accumulating Totals in a Loop

In this exercise, you use what you have learned about using counters and accumulating totals in a loop. Study the following code, and then answer Questions 1-4. The complete program is saved in the file named Rainfall.java. You may want to compile and execute the program to help you answer these questions.

1. What happens when you compile this program if the variable sum is not initialized with the value 0?

_____________________________________________________________________________________

2. Could you replace sum += rainfall ; with sum = sum + rainfal ; ?

_____________________________________________________________________________________

3. The variables sum and average should be declared to be what data type to calculate the most accurate average rainfall?

_____________________________________________________________________________________

4. Could you replace DAYS_IN_WEEK in the statement average = sum / DAYS_IN_WEEK; with the variable named counter and still get the desired result? Explain.

_____________________________________________________________________________________

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 5
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT