package com.epfox.array;publicclassArrayDemo03{publicstaticvoidmain(String[] args){int[] arrays ={1,2,3,4,5};//打印全部的数组元素for(int i =0; i < arrays.length; i++){
System.out.println("i="+ arrays[i]);}//计算所有元素的和int sum =0;for(int i =0; i < arrays.length; i++){
sum += arrays[i];}
System.out.println("sum="+ sum);//查找最大元素int max = arrays[0];for(int i =1; i < arrays.length; i++){if(arrays[i]> max){
max = arrays[i];}}
System.out.println("max="+ max);}}
package com.epfox.array;publicclassArrayDemo04{publicstaticvoidmain(String[] args){int[] arrays ={1,2,3,4,5};//Java1.5开始出现,不能获取下标// for (int array : arrays) {// System.out.println(array);// }printArray(arrays);printArray(reverse(arrays));}//使用方法打印数据元素publicstaticvoidprintArray(int[] arrays){for(int i =0; i < arrays.length; i++){
System.out.println(arrays[i]);}}//数组反转publicstaticint[]reverse(int[] arrays){int[] result =newint[arrays.length];for(int i =0,j = result.length-1;i < arrays.length; i++, j--){
result[j]= arrays[i];}return result;}}