java代码,输入n多个数,求其平均值,虽有重复,但是第二次,我就乱写了

总结:对象调用方法,与在main 里直接输出没什么大的区别,少用方法,

乱搞++++

package com.c2;

import java.util.Scanner;

public class DD {

	// 求数组的平均值即 :a[i]/a.length

	public static void main(String[] args) {
		Scanner c = new Scanner(System.in);
		int a[] = new int[4];
		DD b = new DD();
		// DD d=new DD();
		/*
		 * System.out.println("请输入10个数-----"); int b=c.nextInt(); int
		 * b1=c.nextInt(); int b2=c.nextInt(); int b3=c.nextInt(); int
		 * b4=c.nextInt();
		 */// 很sb啊。这么手打出来会累,会繁琐,不如用循环.比如放入10000个数,我难道要写10000行、??
		double s = 0;
		for (int i = 0; i < a.length; i++) {
			System.out.println("请输入第" + (i + 1) + "个数---");
			a[i] = c.nextInt();
			s += a[i];
			// System.out.println(""+s);

		}
		System.out.println("平均值为:" + s / a.length);
		System.out.println("总和为:" + s);

	}

}

  

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