(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; Declare one-dimensional array
score=new int[3];//Allocate space with a length of 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[]=new int score[3]; Write array declaration and allocate memory on one line
(ii) Transfer parameters
Because of beginner Java, this is only a discussion of value delivery, regardless of address delivery. There are 3 main points:
· The argument is the array name;
· The parameter is a newly declared array, and if there is a return value, add the bracket "[]" after the type of the function;
· The return value is an 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 a small set of Java in the introduction of the array of the creation and communication methods, I hope to help everyone, if you have any questions welcome to my message, small series will promptly reply to everyone!