编写一个java程序cxsz.java，求一个整数数组的最大值、最小值和平均值。整数数组的值为{12

0

My1st、鹏 | 初学一级 | 园豆：145

0
`//test public static void main(String[] args) {        int[] ti={12,51,23,4,72,34,7,25,78,61};    cxsz.testNumber(ti);     }public class cxsz {//求最小、最大、平均、和public static void testNumber(int[] par) {        int min = par[0], max = par[0], sum = 0, ave = 0;        for (int i = 0; i < par.length; i++) {            if (min > par[i]) {                min = par[i];            }            if (max < par[i]) {                max = par[i];            }            sum = sum + par[i];        }        ave = sum / par.length;        System.out.println("最小数：" + min);        System.out.println("最大数：" + max);        System.out.println("平均数：" + ave);        System.out.println("和：" + sum);    }}`

run:

0
` 1 public class Cxsz{ 2     public static void main(String[] args){ 3         int[] array = new int[]{12,51,23,4,72,34,7,25,78,61}; 4         int min=array[0],max=array[0],avg=array[0]; 5         int sum = 0; 6         for(int i=0;i<array.length;i++){ 7             if(array[i]>max) 8                 max = array[i]; 9             if(array[i]<min)10                 min = array[i];11             sum += array[i];12         }13         avg = sum/array.length;14         System.out.println("数组的最大值为:"+max);15         System.out.println("数组的最小值为:"+min);16         System.out.println("数组的平均值为:"+avg);17     }18 }`

您需要登录以后才能回答，未注册用户请先注册