004-004-010

Assigning Values to an Array and Computing the Sum

Easy

Problem Description

Assigning Values to an array and Computing the Sum

In this problem, you will create a program that assigns fixed values to each element of an int array, computes the total sum using a for loop, and displays the result to standard output.

Learning Objective: Understand assigning values to array elements and computing a sum with a loop

Overview

Create an int array, assign values to each element, and print the sum.

Specifications

  1. Create an int[] array of size 5
  2. Assign 10, 20, 30, 40, 50 to indices 0-4
  3. Compute the sum with a for loop
  4. Print the sum as Sum: 150

Output Format

Sum: 150

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up