004-002-016
Array Iteration
Medium
Problem Description
array Iteration
In this problem, you will create a program that iterates over an int array using a standard for loop to display each index and value, then calculates and displays the total sum using an enhanced for loop.
Learning Objective: Understand array iteration using for loops and enhanced for loops
Overview
Java provides two ways to iterate over array elements: the standard for loop (index-based) and the enhanced for loop (for-each). Each is suited to different use cases.
Specifications
- Declare an int array {10, 20, 30, 40, 50}
- Display index and value using standard for loop
- Calculate and display the sum using enhanced for loop
Output Format
[0]: 10
[1]: 20
[2]: 30
[3]: 40
[4]: 50
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