6)Use array sum of integers and find the sum and average of the elements of that array in java

PHOTO EMBED

Mon Jul 08 2024 06:02:27 GMT+0000 (Coordinated Universal Time)

Saved by @varuntej #java

public class ArraySumAverage {
    public static void main(String[] args) {
        // Predefined array of integers
        int[] array = { 10, 20, 30, 40, 50 };

        // Calculate sum and average
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        double average = (double) sum / array.length;

        // Output: Sum and Average
        System.out.println("Sum of the elements: " + sum);
        System.out.println("Average of the elements: " + average);
    }
}
content_copyCOPY