004-006-004
Array Assignment: Sharing Arrays
Medium
Problem Description
Array Assignment: Sharing Arrays
Learning Objective: Understand that array assignment shares the reference
Overview
When you assign an array variable to another, they share the same array. Changes in one affect the other.
Specifications
- Initialize array original with {1, 2, 3}
- Assign original to copy
- Change copy[0] to 100
- Display original[0] and copy[0]
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) {
// 元の配列
int[] original = {1, 2, 3};
// 配列 代入ment (sharing reference)
int[] copy = original;
// 変更: で copy affects original
copy[0] = 100;
// 両方: become 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
