java代码----求最大值,平均值。。。

总结:方法的返回值----返回的对象到底是什么?

package com.a;

import java.util.Scanner;

//从键盘输入10个数,并输出最大值,最小值,平均值
public class Zou {
	public static double ccc(int a[]) {
		int s = 0;
		int max = a[2];
		for (int i = 0; i < a.length; i++) {

			if (max < a[i]) {
				max = a[i];
			}

		}
		return max;
	}

	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		int a[] = new int[10];
		Zou z = new Zou();

		// int a[]={2,4,6};
		int s = 0;
		for (int i = 0; i < a.length; i++) {
			System.out.println("请输入第" + (i + 1) + "个数---");
			// int b=c.nextInt();//此处意为输入单个的数,另外一个一个的输出
			a[i] = c.nextInt();// 此处意为这输入一个数组内的数,是两个概念,因为不懂所以一直犯错
			s += a[i];

		}

		System.out.println("平均值:" + s / a.length);
		System.out.println("总值:" + s);
		System.out.println("最大值为:" + z.ccc(a));// 对象调用方法名

	}

}

  

原文地址:https://www.cnblogs.com/langlove/p/3398381.html