JAVA-array definition
Array definition
An array is an ordered collection of data of the same type.
The array describes several data of the same type, arranged and combined in a certain order.
Among them, each data is called an array element, and each array element can be accessed through a subscript.
public class ArrayDemo1 {
public static void main(String[] args) {
int[] nums;
nums = new int[10];
nums[0]=1;
nums[1]=2;
nums[2]=3;
nums[3]=4;
nums[4]=5;
nums[5]=6;
nums[6]=7;
nums[7]=8;
nums[8]=9;
nums[9]=10;
System.out.println(nums[9]);
int sum=0;
for (int i = 0; i <nums.length ; i++) {
sum=nums[i]+sum;
}System.out.println("总和为:"+sum);
}
}