Bird
0
0

You want to record the temperature for each day of a week and then compute the average temperature. Which approach using arrays is best in Java?

hard📝 Application Q8 of 15
Java - Arrays
You want to record the temperature for each day of a week and then compute the average temperature. Which approach using arrays is best in Java?
ACreate an array of size 30 to store temperatures for the month
BUse separate variables for each day and add them manually
CCreate an array of size 7, store each day's temperature, then sum and divide by 7
DUse a single variable to store the total temperature without storing daily values
Step-by-Step Solution
Solution:
  1. Step 1: Understand the requirement

    We need to store temperatures for 7 days and calculate the average.
  2. Step 2: Evaluate options

    Create an array of size 7, store each day's temperature, then sum and divide by 7 correctly uses an array of size 7 to store daily temperatures and compute the average. Use separate variables for each day and add them manually is inefficient. Create an array of size 30 to store temperatures for the month uses an unnecessarily large array. Use a single variable to store the total temperature without storing daily values loses individual day data.
  3. Final Answer:

    Create an array of size 7, store each day's temperature, then sum and divide by 7 -> Option C
  4. Quick Check:

    Use array size matching data count for calculations [OK]
Quick Trick: Use array sized to data count for calculations [OK]
Common Mistakes:
  • Using separate variables instead of arrays
  • Creating arrays larger than needed
  • Not storing individual day values before averaging

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes