(I) Creation of array
The creation of an array includes two parts: the declaration of the array and the allocation of memory space.
int score[]=null; //Declare the one-dimensional array score=new int[3]; //Allocate space with length 3
There is another way to declare an array:
int[] score=null; //Write the brackets before the array name
Usually, when writing code, for convenience, we merge two lines into one line:
int score[]=new int score[3]; //Write the array declaration and allocated memory in one line
(II) Passing parameters
Since you are a beginner in Java, only value transfer is discussed here, and address transfer is not considered. There are 3 main points:
・ The actual parameter is the array name;
・ The formal parameters are newly declared arrays. If there is a return value, the bracket "[]" must be added to the function type;
・ The return value is the array name.
Examples are as follows:
/*** Created by lijiaman on 2016/9/16.*/public class createArray2{public static void main(String[] args){int score[]=null;score=new int[3];int speed[]={12,35};for(int x=0;x<3;x++){score[x]=x*2+1;}for(int x=0;x<3;x++){System.out.println("score["+x+"]="+score[x]);}System.out.println("length:"+score.length);for(int x=0;x<speed.length;x++){System.out.println("Speed:"+speed);}}}}The above is the method of creating and passing arrays in Java introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message. The editor will reply to you in time!