006-001-010
For Loop: Process Array Elements
Hard
Problem Description
for loop: Process array Elements
In this problem, you will create a program that reads the count and each integer from standard input using Scanner, iterates over all elements using a for loop, outputs each element in order, and displays the total and average to standard output.
Learning Objective: Understand how to process all array elements using a for loop
Overview
Create a program that reads the array size and elements from standard input, outputs all of them, and calculates the total and average.
Input Format
N
a1
a2
...
aN
- Line 1: number of elements N (1 ≤ N ≤ 100)
- Subsequent lines: each integer (one per line)
Output Format
Score 1: a1
Score 2: a2
...
Score N: aN
Total: total
Average: average (1 decimal place)
Sample Input/Output
Input:
5
85
92
78
90
88
Output:
Score 1: 85
Score 2: 92
Score 3: 78
Score 4: 90
Score 5: 88
Total: 433
Average: 86.6
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