Java Fundamentals 08

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.