Title: Writing Java programs, creating arrays arr1 and arr2, copying the elements of the array arr1 in the index position of 0-3 into the array arr2, and finally outputting the elements in the array arr1 and ARR2.
Packagesix;Importjava.util.Arrays; Public classsixonefive { Public Static voidMain (string[] args) {int[] arr1={1,2,3,4}; int[] Arr2=arrays.copyofrange (arr1,0,3); System.out.println ( "arr1:"); for (int j=0;j<arr1.length;j++) {//iterates through an array is to get each element in the array. Usually iterating through an array is implemented with a for loop, and traversing a two-dimensional array requires a double for loop, with the length property of the array to System.out.print ("\ t" + arr1[j]);//"\ T" is an escape character, represents a vertical tab, moves the cursor to the next tab position} System.out.println ();
System.out.println ( "ARR2:"); for (int i=0;i<arr2.length;i++) {System.out.print ("\ t" +Arr2[i]); } System.out.println (); }}
The results of the operation are as follows:
6th Array Copy Array