English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
(I) Criação de arrays
A criação de arrays inclui duas partes: a declaração do array e a alocação de espaço de memória.
int score[]=null; //declarar um array unidimensional score=new int[3}; //alocar o comprimento de3espaço
A declaração de arrays pode ser feita de outra maneira:
int[] score=null; //Write the square brackets in front of the array name
Generally, in writing code, for convenience, we merge the two lines into one line:
int score[]=new int score[3}; //Write the declaration and memory allocation of the array in one line
(II) Passing parameters
Since this is an introduction to Java for beginners, we will only discuss value passing and not address passing. Mainly3Point:
· The actual parameter is the array name;
· The formal parameter is the newly declared array. If there is a return value, add square brackets "[]" after the function type;
· The return value is the array name.
Example:
/** * 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 introduction of the creation and parameter passing method of arrays in Java introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time!
Declaration: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @ to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)