002-001-013

Loop Input and Aggregation with Scanner

Hard

Problem Description

Loop Input and Aggregation with Scanner

In this problem, you will create a program that reads a count N followed by N integers using Scanner, computes their sum and average (one decimal place), and displays the result to standard output.

Learning Objective: Understand how to process multiple line inputs using Scanner with loops

Overview

Create a program that reads a count N, then N integers, and prints their sum and average.

Specifications

  1. Read the count N from the first line
  2. Read N integers, one per line
  3. Print the sum as Sum: <value>
  4. Print the average as Average: <value> (one decimal place)

Input Example

3
10
20
30

Output Format

Sum: 60
Average: 20.0

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