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.
_____________________________________________________________________________________
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.