public class Demo01 {
public static void main(String[] args) {
int [] nums;//1.声明一个数组
nums =new int[10];//2.创建一个数组
//声明并创建一个数组 int [] nums2 =new int[10];
//3.给数组元素中赋值
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;
//计算所有元素的和
int sum=0;
for (int i =0;i<nums.length;i++){
sum =sum +nums[i];
}
System.out.println("和为:"+sum);
}
}
标签:10,nums,int,创建,数组,声明 From: https://www.cnblogs.com/anonymity12/p/18147304