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

Academics

AI-Powered learning for Grades 8–12, aligned with major Indian and international curricula.

Academics
Professionals

Professional Courses

Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.

Professional Courses
Games

Interactive Games

Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.

games

Practice Questions

Test your understanding with targeted questions related to the topic.

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!

Practice 4 more questions and get performance evaluation

Interactive Quizzes

Engage in quick quizzes to reinforce what you've learned and check your comprehension.

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.

Solve and get performance evaluation

Challenge Problems

Push your limits with challenges.

Question 1

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.

Question 2

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.

Challenge and get performance evaluation