public class ArrayDemo03 { public static void main(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+=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); } }
public class ArrayDemo05 { public static void main(String[] args) { int[] arrays = {1, 2, 3, 4, 5}; int[] result = reserve(arrays); for(int i=0;i<arrays.length;i++){ System.out.print(result[i]); } } // 反转数组 public static int[] reserve(int[] arrays) { int[] result = new int[arrays.length]; for (int i = 0; i < arrays.length; i++) { result[i] = arrays[arrays.length - 1 - i]; } return result; } }
标签:Java,05,arrays,max,System,int,数组,println,out From: https://www.cnblogs.com/sankouyitouju/p/17837531.html