(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