1.
2. Naming Methods for arrays
1) int[]ages=new int[5];
2) Int[]ages;
Ages=new Int[5];
3, Java does not support different types of duplicate names array
4. Cyclic assignment of arrays in Java
1 PackageDierge;2 3 Public classShuzu {4 5 Public Static voidMain (String args[]) {6 int[]ags=New int[5];7 inti;8 for(i=0;i<ags.length;i++){9ags[i]=i;TenSystem.out.println ("ags[" +i+ "] is:" +ags[i]); One } A - - the } - -}
The printing results are as follows:
Ags[0] is: 0
AGS[1] is: 1
AGS[2] is: 2
AGS[3] is: 3
AGS[4] is: 4
5. Initial values for various types of arrays
The code is as follows:
1 PackageDierge;2 3 Public classShuzu {4 5 Public Static voidMain (String args[]) {6 int[]ags=New int[1];7SYSTEM.OUT.PRINTLN ("The default value for an array of type int is:" +ags[0]);8 Boolean[]a=New Boolean[1];9SYSTEM.OUT.PRINTLN ("The default value of the Boolean array is:" +a[0]);Ten byte[]b=New byte[1]; OneSYSTEM.OUT.PRINTLN ("The default value for an array of type Byte is:" +b[0]); A Short[]c=New Short[1]; -SYSTEM.OUT.PRINTLN (the default value for an array of type short is: "+c[0]); - Char[]d=New Char[1]; theSYSTEM.OUT.PRINTLN (the default value for an array of type char is: "+d[0]); - Long[]e=New Long[1]; -SYSTEM.OUT.PRINTLN ("The default value for an array of type Long is:" +e[0]); - float[]f=New float[1]; +SYSTEM.OUT.PRINTLN (the default value of the "float type array" is: "+f[0]); - Double[]g=New Double[1]; +SYSTEM.OUT.PRINTLN ("The default value for an array of type Double is:" +g[0]); A at - - - - - } in -}
The printing results are as follows:
The default value for an array of type int is: 0
The default value for an array of type Boolean is: false
The default value for an array of type Byte is: 0
The default value for array of type short is: 0
The default value for an array of type char is:
The default value for an array of type Long is: 0
The default value for an array of type float is: 0.0
The default value for an array of type Double is: 0.0
Knowledge about arrays in Java