008-005-011
Modifying Arrays via Reference Arguments
Hard
Problem Description
Modifying Arrays via Reference Arguments
In this problem, you will create a program that implements a doubleAll method to double each element of an array, and displays the array before and after modification to standard output.
Learning Objective: Understand the effect of modifying arrays through pass-by-reference
Overview
Modify an array inside a method and verify the effect on the caller.
Input Format
n
a1 a2 ... an
- Line 1: number of elements n
- Line 2: n space-separated integers
Specifications
- Define doubleAll(int[] numbers) method
- Double each element of the array
- Output the array before and after modification
Output Format
Before: a1 a2 ... an
After: b1 b2 ... bn
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