Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to use arrays in java? There are only four steps to manipulate arrays in java: 1, and declare array syntax: data.
How to use arrays in java? There are only four steps to manipulate arrays in java: 1, and declare array syntax: data.
Public? Class? A {

Public? Static electricity Invalid? main(String[]? args){

//Method 1

int? a[]; //Declare a file named.

A = new? int[3]; //Create a storage space for 3 integers for an integer array named A..

a[0]= 2; //Assign a value of 2 to an integer with an angle of 0 in an integer array named a..

a[ 1]= 5; //Assign 5 to the integer of 1 in the integer array named a..

a[2]= 7; //Assign a value of 7 to an integer with two corners in an integer array named a..

//Method 2

int? B[]= New? int[3]; //Declare an integer array named b and create three integer storage spaces for this integer array.

b[0]= 2; //Assign 2 to the integer with angle 0 in the integer array named b..

b[ 1]= 5; //Assign 5 to the integer of 1 in the integer array named b..

b[2]= 7; //Assign a value of 7 to an integer with two angles in an integer array named b..

//Method 3

int? C [] = {2,5,7}//Declare an integer array named C and create three integer storage spaces for this integer array at the same time. Assign the integer value of the 0-corner marker to 2, 1 the integer value of the corner marker to 5, and the integer value of the 2-corner marker to 7.

//Method 4

int? D[]= New? int[]{2,5,7 }; //Declare an integer array named d and create three integer storage spaces for this integer array at the same time. Assign the integer value of the 0-corner marker to 2, 1 corner marker to 5, and the integer value of the 2-corner marker to 7.

//Note: The results of the above methods are the same, but the array names are different.

}

}