package com.ctgu.java.exer; public class TestArray3 { public static void main(String[] args){ int[] arr = new int[]{12,43,9,0,-65,-99,100,9}; int max = arr[0]; for(int i = 1; i < arr.length;i++ ){ if(max < arr[i]){ max = arr[i]; } } System.out.println("数组最大值为:" + max); int min=arr[0]; for(int i = 1;i< arr.length;i++){ if(min >arr[i]){ min = arr[i]; } } System.out.println("数组最小值为:" + min); int sum = 0; for(int i = 0; i < arr.length; i++){ sum +=arr[i]; } System.out.println("总和为:" +sum); int avg = 0; avg = sum / arr.length; System.out.println("平均数为:" +avg ); // 数组元素复制 int [] arr1 = new int[arr.length]; for(int i = 0 ; i < arr1.length;i++){ arr1[i] = arr[i]; } //数组元素的反转 //for(int i = 0; i< arr.length/2 ; i++){ //int temp =arr[i]; //arr[i] = arr[arr.length-1 - i]; //arr[arr.length-1-i]=temp; //} //反转2 for(int x = 0 , y = arr.length - 1; x < y;x++,y--){ int temp = arr[x]; arr[x] = arr[y]; arr[y] = temp ; } for(int i = 0; i < arr.length; i++){ System.out.print(arr[i] + "\t"); } } }
原文地址:http://9815936.blog.51cto.com/9805936/1601352