Practice Array Example – Sum of Elements - 6.6 | Chapter 6: Arrays and Strings in Java | JAVA Foundation Course
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

Array Example – Sum of Elements

6.6 - Array Example – Sum of Elements

Enroll to start learning

You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.

Learning

Practice Questions

Test your understanding with targeted questions

Question 1 Easy

What is an array in Java?

💡 Hint: Think about how an array stores data.

Question 2 Easy

How do you declare an array in Java?

💡 Hint: Remember the syntax we discussed!

4 more questions available

Interactive Quizzes

Quick quizzes to reinforce your learning

Question 1

What is the output of the following code: int[] arr = {10, 20, 30}; int sum = 0; for (int num : arr) { sum += num; } System.out.println(sum);?

60
30
20

💡 Hint: Add the values of the numbers in the array.

Question 2

True or False: The index of the first element in an array starts at 1.

True
False

💡 Hint: Remember how indexing works in programming.

Get performance evaluation

Challenge Problems

Push your limits with advanced challenges

Challenge 1 Hard

Write a program that creates an array of your five favorite food items and then displays a message that combines all of them together.

💡 Hint: Remember how to use loops to go through each item of the array.

Challenge 2 Hard

Create an array of ten random numbers, sum them, and then find the average. Include error checks for ensuring all numbers are valid.

💡 Hint: Use a method to validate the numbers and another to calculate both sum and average.

Get performance evaluation

Reference links

Supplementary resources to enhance your learning experience.