java代码,输入n多个数,求其平均值,虽有重复,但是第二次,我就乱写了
2024-09-01 04:59:16
总结:对象调用方法,与在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); } }
最新文章
- java.lang.IllegalArgumentException: &#39;sessionFactory&#39; or &#39;hibernateTemplate&#39; is required
- MVC 多语言记录1 设置默认的ResourceType
- swiper 技巧
- JAVA基础学习之XMLCDATA区、XML处理指令、XML约束概述、JavaBean、XML解析(8)
- https和http共存的nginx配置
- 常见设计模式解析和实现(C++)Prototype模式(原型模式)
- 【HDU】 1018 Big Number
- NopCommerce 3.3中文语言包发布下载及使用
- Delphi 获取北京时间(通过百度和timedate网站)
- 【转】CodeGear RAD 2007 SP4
- DateTime.ParseExact
- 《CLR Via C#》读书笔记,持续更新...
- MongoDB存储引擎(下)——In-Memory
- 织梦cms网上复制图片不可用的解决方法
- Python系列-python函数
- 关联管理器(RelatedManager)
- 神经网络中的偏置项b到底是什么?
- Ruler.java
- MATLAB 的unique函数——数组矩阵的唯一值
- linux常用命令:sudo 命令