004-005-008

Array Copy: Data Backup

Easy

Problem Description

Array Copy: Data Backup

In this problem, you will create a program that reads array elements from standard input, duplicates the array as an independent copy using Arrays.copyOf(), and verifies that modifying the original does not affect the copy.

Learning Objective: Understand array copy methods and reference differences

Overview

Read array elements and a new value from standard input, then verify that modifying the original array does not affect the copied array.

Input Format

a b c
newVal
  • Line 1: Three integers (space-separated) — initial values for the array
  • Line 2: One integer — new value to assign to the first element of the original array

Specifications

  • Create integer array original from input values
  • Use Arrays.copyOf() method to copy the array
  • Change the first element of the original array to newVal
  • Output the first element of both original and copied arrays

Output Format

Original: [value after change]
Copy: [value at time of copy]

Sample I/O

Input:
10 20 30
99

Output:
Original: 99
Copy: 10

Hint: You need to import the java.util.Arrays class.

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