bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java How To's
Java•Java How To's

Java How To Calculate the Sum of Elements

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);

Previous

Java How To - Character Frequency in a String

Next

Java How To Find the Average of Array Elements