6th Array Copy Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.