Java – For-Each Loop (Sum Example)

Sum of array elements:
Example:

int[] numbers = {1, 2, 3, 4, 5};
int sum = 0;
for (int num : numbers) {
sum += num;
}
System.out.println("Total: " + sum);

No images available.