计算int数组中的最大,最小,平均值
public static void testNumber(int[] arr) {
int max = arr[0];
int min = arr[0];
int avg = 0;
int sum = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
if (arr[i] < min) {
min = arr[i];
}
sum += arr[i];
}
avg = sum / arr.length;
network.append("最大:" + max + "ms\n");
network.append("最小:" + min+ "ms\n");
network.append("平均:" + avg+ "ms\n");
计算int数组中的最大,最小,平均值的更多相关文章
- LeetCode刷题笔记(6)按照索引计算int[] 数组中的和([Time Limit Exceeded]问题)
Easy303 Easy633 package easy; public class e303 { private int[] sums; public e303(int[] nums) { sums ...
- C语言 选择排序算法原理和实现 从数组中 找出最小的元素然后交换位置
#include <stdio.h> int main(void) { /* 选择排序算法 原理:从数组中 找出最小的元素然后交换位置: */ int a[10] = {9,5,10,7, ...
- MergeSort归并排序和利用归并排序计算出数组中的逆序对
首先先上LeetCode今天的每日一题(面试题51. 数组中的逆序对): 在数组中的两个数字,如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.输入一个数组,求出这个数组中的逆序对的总数. ...
- 数组中找出最小的K个数
题目 给出一个数组,找出K个最小的值 例如给出数组{5,2,4,3,1},给定K值3,则输出结果为{2,3,1} 程序 先给出第一个版本的程序 public static void printKNum ...
- C#-求int数组中连续偶数列的个数
例如:[3, 3, 2, 2, 2, 4, 3, 5, 4, 6, 3]=>2,2,2,4;4,6 结果为2 [3, 3, 2,3, 2, 2, 4, 3, 5, 4, 6, 3]=&g ...
- leetcode-575-Distribute Candies(计算一个数组中元素的种类的快速方法)
题目描述: Given an integer array with even length, where different numbers in this array represent diffe ...
- C语言计算字符串数组中每个字符串出现的个数
unsigned int str_num(char *str[], int num[], int len) { int i, j; int count; int flag[len]; ; i < ...
- 算法题:int 数组中 只有一个是id 只出现一次 其他都出现2次 怎么找出只出现一次的id
首先讲一个最笨的算法:时间复杂度为N 空间复杂度为N 代码如下:输出结果id=3完全正确: int[] a = new int[] { 1, 1, 2, 2, 3, 4, 4 }; Dictiona ...
- 使用js获取数组中最大、最小的数字
1.查询最大值 var maxValue=Math.max.apply(Math,array); 2.查询最小值 var minValue=Math.min.apply(Math,array);
随机推荐
- SQL SUM() 函数
SUM() 函数 SUM 函数返回数值列的总数(总额). SQL SUM() 语法 SELECT SUM(column_name) FROM table_name SQL SUM() 实例 我们拥有下 ...
- Java 通过地址获取经纬度 - 高德地图
一.添加依赖 <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-v ...
- 监控redis
[4ajr@redis1 scripts]$ cat redismonitor.sh #!/bin/bash #想要什么监控项再添加 rediscli="/soft/redis/bin/re ...
- 2018-2019-2 20175228实验一《Java开发环境的熟悉》实验报告
一.实验内容及步骤 (一)使用JDk编译.运行简单的Java程序 实验步骤如下: 实验截图如下: (二)使用IDEA调试程序 1.设置断点2.单步运行:Step Into(快捷捷F7)和Step Ov ...
- MongoDB install
下载地址1:https://www.mongodb.org/dl/linux下载地址2:https://www.mongodb.com/download-center/community关于Mongo ...
- Kaggle教程——大神教你上分
本文记录笔者在观看Coursera上国立经济大学HLE的课程 How to win a data science competetion中的收获,和大家分享.课程的这门课的讲授人是Kaggle的大牛, ...
- JQuery 获取select 的value值和文本值
<select name="month" id="selMonth"> <option value="1">一 ...
- ssh远程 和 上传/下载工具
常用的ssh远程工具有: putty : 软件体积小,开源免费. xshell : 功能强大,亦有免费试用版本 SecureCRT : 功能强大 ftp : 该软件用于上传下载文件 通过ssh ...
- "unexpected console statement” in Node.js
.eslintrc.js module.exports = { rules: { 'no-console': 'off', }, };
- Excel Foundation Install
安装Excel API 函数库 1. 通过下载工具下载函数库 下载 ExcelAPI函数库更新工具 下载 ExcelAPI函数库离线包 ExcelAPI(WPS)函数库离线包 Exc ...