When a program requires more than one variable of the same type to hold the program state, consider using an array to hold the variables. When an array is initialized, it is equivalent to defining multiple variables of the same type.
Int[] A >int:int[] array of elements equivalent to the variable child of type int.
String[] An element of an >string:string[] array is equivalent to a variable of type String.
Person[] A >person:person[] array of elements equivalent to the person type of the child.
Int[][] >int[]: int[][] An element of an array is equivalent to a variable of type int[].
class cat{
Public double weight;
Public int age;
Public Cat (double weight,int age) {
this. weight=weight;
this. age=age;
}
}
Public class DD {
Public Static void Main (string[] args) {
Define and dynamically initialize-a
int[] array
int [] arr= new int[5];
Use loops to Yuansu values for each array
for (int i=0; i<</span>arr.length;i++) {
arr[i]= (i+1) * *;
}
For
The meta-home of the Pos array, used exactly the same as the normal change F
The following can either give the value of the array meta-bin to
int to F, you can also
int variable f value bin to array element cable
int a=arr[1];
int b=20;
B=a;
Arr[2]=b;
Define and dynamically initialize a cat[] array
Cat[] cats=new cat[2];
cats[0]=New Cat (3.34, 2);
cats[1]=New Cat (3.2,2);
The value of the 1th element of the Cats array is given by bin
Cl
Cat C1=cats[0];
Cat c2=New Cat (4.3,3);
C2 Value bin to the 2nd element of the Cats array
CATS[1]=C2;
}
}
Java Fundamentals 08