004-006-003
Array Assignment: Reference Copy
Easy
Problem Description
Array Assignment: Reference Copy
Learning Objective: Understand that array assignment copies the reference, not the content
Overview
When you assign an array variable to another variable, the reference (memory location) is copied, not the array content. Therefore, changing one array affects the other.
Specifications
- Initialize integer array
originalwith {10, 20, 30} - Assign
originalto another array variablecopy - Change
copy[0]to 100 - Output the first element of both arrays
Output Format
original[0]: 100
copy[0]: 100
Test Cases
※ Output examples follow programming industry standards
Input:
Expected Output:
original[0]: 100 copy[0]: 100
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
›
⌄
⌄
public class Main {
public static void main(String[] args) {
// original 配列を初期化
int[] original = {10, 20, 30};
// 代入: 配列 変数 (reference copy)
int[] copy = original;
// copy's 要素を変更
copy[0] = 100;
// 両方の配列の最初の要素を出力
System.out.println("original[0]: " + original[0]);
System.out.println("copy[0]: " + copy[0]);
}
}
0 B / 5 MB
You have 10 free executions remaining
