Java Learning Summary (1)-creation and argument of arrays

Source: Internet
Author: User

(i) Creation of arrays

The creation of an array consists of two parts: the declaration of an array and the allocation of memory space.

int score[]=null// declaration one-dimensional array score=newint//  Allocate a space of length 3

There is another way to declare an array:

int [] score=null// write the brackets in front of the array name

In general, when writing code, for convenience, we combine two lines into one line:

int score[]=newint// writes the array declaration to the allocated memory in one line

(ii) Transfer parameters

As a beginner of Java, only value passing is discussed here, regardless of address delivery. There are 3 main points:

· An argument is an array name;

· The formal parameter is the newly declared array, and if there is a return value, add the brackets "[]" after the type of the function.

· The return value is the array name.

Examples are as follows:

/*** Created by Lijiaman on 2016/9/16.*/ Public classcreatearray2{ Public Static voidMain (string[] args) {intscore[]=NULL; Score=New int[3]; intSpeed[]={12,35};  for(intx=0;x<3;x++) {Score[x]=x*2+1; }         for(intx=0;x<3;x++) {System.out.println ("score[" +x+ "]=" +score[x]); } System.out.println ("Length:" +score.length);  for(intx=0;x<speed.length;x++) {System.out.println ("Speed:" +Speed ); }    }}

Java Learning Summary (1)-creation and argument of arrays

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.