求数组的平均值 Exercise07_08
import java.util.Scanner;
/**
* @author 冰樱梦
* 时间:2018年下半年
* 题目:求数组的平均值
*
*/
public class Exercise07_08 {
public static void main(String[] args){
Scanner input=new Scanner(System.in);
double[] array=new double[10];
System.out.println("输入10个double型的数");
for(int i=0;i<array.length;i++){
array[i]=input.nextDouble();
}
System.out.print(average(array));
} //求int类型的数组的平均值
public static int average(int[] array){
int total=0;
for(int i=0;i<array.length;i++){
total+=array[i];
}
return total/array.length;
} //求double类型的数组的平均值
public static double average(double[] array){
double total=0;
for(int i=0;i<array.length;i++){
total+=array[i];
}
return total/array.length;
}
}
求数组的平均值 Exercise07_08的更多相关文章
- shell 求数组的平均值,求和,最大值,最小值
test.sh #!/bin/bash arr=( ) let min=${arr[]} let max=${min} sum= ;i<${#arr[*]};i++)) do [[ ${min} ...
- 使用基础知识完成java小作业?强化练习-1.输入数组计算最大值-2.输出数组反向打印-3.求数组平均值与总和-4.键盘输两int,并求总和-5.键盘输三个int,并求最值;
完成几个小代码练习?让自己更加强大?学习新知识回顾一下基础? 1.输入数组计算最大值 2.输出数组反向打印 3.求数组平均值与总和 4.键盘输两int,并求总和 5.键盘输三个int,并求最值 /* ...
- Python简单计算数组元素平均值的方法示例
Python简单计算数组元素平均值的方法示例 本文实例讲述了Python简单计算数组元素平均值的方法.分享给大家供大家参考,具体如下: Python 环境:Python 2.7.12 x64 IDE ...
- [LeetCode] Find Peak Element 求数组的局部峰值
A peak element is an element that is greater than its neighbors. Given an input array where num[i] ≠ ...
- C++ 数组长度 以及 数组名作为参数传递给函数 以及 为什么不在子函数中求数组长度
在看排序,首先是插入排序,思路理清后想用代码实现,然后问题来了: 如何求数组长度? 如果没记错,在Java中应该是有直接可用的方法的, Python中(序列)也有.len,在C/C++中,字符串倒是有 ...
- C#中求数组的子数组之和的最大值
<编程之美>183页,问题2.14——求子数组的字数组之和的最大值.(整数数组) 我开始以为可以从数组中随意抽调元素组成子数组,于是就有了一种想法,把最大的元素抽出来,判断是大于0还是小于 ...
- 《github一天一道算法题》:分治法求数组最大连续子序列和
看书.思考.写代码. /*************************************** * copyright@hustyangju * blog: http://blog.csdn. ...
- PHP使用array_intersect()函数求数组交集
在PHP中求数组的交集,我们可以与PHP给我们提供的现成函数:array_intersect(),其用法格式为: array array_intersect(array array1,array ar ...
- 求数组的最小数、最大值,求一组数的平均数,sort函数详解,类数组转数组
求数组的最小值和最大值 //求数组当中最大值和最小值 var arr=[3,2,6,1,45,23,456,23,2,6,3,45,37,89,30]; //第一种方法 根据排序方法来求最大值和最小值 ...
随机推荐
- ButterKnife用法详解
http://www.cnblogs.com/zhaoyanjun/p/6016341.html 本文出自[赵彦军的博客] 前言 ButterKnife 简介 ButterKnife是一个专注于And ...
- 【EverydaySport】健身笔记——动态牵拉
动态牵拉,包含了动态和牵拉两个概念.动态牵拉要求牵拉的过程要伴随着走路,即行进中牵拉,动态牵拉不仅可以使得肌肉得到延展,还可以激活肌肉协同工作,发展协调性.灵活性.进行动态牵拉时每个动作要进行5~10 ...
- python实战===一句python代码搭建FTP服务
环境搭建: python windows/linux pip install pyftpdlib (安装失败请到这里下载:https://pypi.python.org/pypi/pyftpdlib ...
- centos_7.1.1503_src_4
http://vault.centos.org/7.1.1503/os/Source/SPackages/ libkcompactdisc-4.10.5-3.el7.src.rpm 05-Jul-20 ...
- expect 实现iterm2自动加载pem登录跳板机
#!/usr/bin/expect set timeout spawn expect { "connecting (yes/no)?" { send "yes\r&quo ...
- 【bzoj4033】HAOI2015树上染色
树形dp. #include<bits/stdc++.h> #define N 2010 using namespace std; typedef long long ll; ,head[ ...
- (转)关于bootstrap, boosting, bagging,Rand forest
转自:https://blog.csdn.net/jlei_apple/article/details/8168856 这两天在看关于boosting算法时,看到一篇不错的文章讲bootstrap, ...
- A Tutorial on Network Embeddings
A Tutorial on Network Embeddings paper:https://arxiv.org/abs/1808.02590 NE 的中心思想就是找到一种映射函数,该函数将网络中 ...
- y=y||'world'与y=y?y:'world'
1.y=y||’world’ function log(x,y){ y=y||’world’; console.log(x,y) } log(‘hello’)===>hello world lo ...
- LeetCode解题报告—— Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and ...