Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java How To Calculate the Sum of Elements?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___[] myArray = {1, 5, 10, 25};Calculate the Sum of an Array
Example
int[] myArray = {1, 5, 10, 25};
int sum = 0;
int i;
// Loop through the array elements and store the sum in the sum variable
for (i = 0; i < myArray.length; i++) {
sum += myArray[i];
}
System.out.println("The sum is: " + sum);