Calculate Average in Java: Explanation & Practice

Find the average of array elements

Problem summary

Calculate the average of elements in [10, 20, 30, 40, 50].

Starter code

public class Main {
    public static void main(String[] args) {
        int[] numbers = {10, 20, 30, 40, 50};
        
        // Calculate and print average
        // Print: Average: <result>
    }
}

Expected output and test cases

  • Average of array
    Average: 30.0

Hints

  1. Sum all elements first
  2. Divide sum by array length
  3. Cast to double for decimal result

Related Arrays exercises

Practice all Arrays exercises · Run this idea in the Java compiler