004-001-011

Passing Arrays to Methods

Hard

Problem Description

Passing Arrays to Methods

In this problem, you will create a program that reads an integer array from standard input, implements methods accepting the array as arguments, computes the average and doubles each element, and displays the results to standard output.

Learning Objective: Understand how to pass arrays as method arguments and return arrays from methods

Overview

Create methods that process arrays and practice array passing.

Input Format

N
a1 a2 ... aN
  • Line 1: number of elements N (1 ≤ N ≤ 100)
  • Line 2: N space-separated integers

Specifications

  • double average(int[] arr): calculates and returns array average
  • int[] doubleValues(int[] arr): returns new array with each element doubled

Output Format

Original: a1 a2 ... aN
Average: avg
Doubled: d1 d2 ... dN

Example

Input:

3
10 20 30

Output:

Original: 10 20 30
Average: 20.0
Doubled: 20 40 60

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