004-010-007

Iterating Over Arrays

Easy

Problem Description

Iterating Over Arrays

Learning Objective: Understand how to process all elements of an array using a standard for loop and an enhanced for loop (for-each)

Overview

Process all elements of an integer array using two approaches (standard for loop and enhanced for loop), outputting the sum and double of each element.

Specifications

  1. Declare an integer array {10, 20, 30, 40, 50}
  2. Use a standard for loop to calculate and print the sum of the array
  3. Use an enhanced for loop (for-each) to print double of each element, one per line

Output Format

Sum: 150
20
40
60
80
100

Ready to Try Running Code?

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

Don't have an account?