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
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