publicclassArrayDemo01{publicstaticvoidmain(String[] args){int[] nums;//1.声明一个数组
nums =newint[10];//2.创建一个数组int[] nums2 =newint[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;System.out.println(nums[4]);//计算所有元素之和int sum =0;//获取数组长度:arrays.lengthfor(int i =0; i < nums.length; i++){
sum = sum + nums[i];}System.out.println("总和为:"+sum);}}
publicclassArrayDemo03{publicstaticvoidmain(String[] args){int[] arrays ={1,2,3,4,5};//打印全部的数组元素for(int i =0; i<arrays.length; i++){System.out.println(arrays[i]);}System.out.println("===========");//打印所有元素的和int sum =0;for(int i =0; i < arrays.length; i++){
sum = sum+arrays[i];}System.out.println("sum="+sum);System.out.println("==========");//查找最大元素int max = arrays[0];for(int i =1; i < arrays.length; i++){if(arrays[i]>max){
max = arrays[i];}}System.out.println("max="+max);}}