004-006-008
Understanding Array Reference Assignment
Easy
Problem Description
Understanding Array Reference Assignment
In this problem, you will create a program that reads three initial array values and one update value from standard input, declares int[] numbers1, assigns it to numbers2, modifies numbers2[0] with the input value, then prints numbers1[0] to demonstrate that both variables share the same reference.
Input format:
- Line 1: Three integers for the initial array (space-separated)
- Line 2: The new value to assign to numbers2[0]
Output format:
numbers1[0]: <value>
Learning Objectives:
- Understand that arrays in Java are reference types
- Confirm that assigning an array variable copies the reference, not the data
- Recognize how reference types behave differently from primitive types
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