Here you can find the source of mean(int[] array)
Parameter | Description |
---|---|
array | Array of integers whose mean is to be computed. |
public static double mean(int[] array)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from ww w . j av a2s. c o m*/ * Computes the mean value of a matrix of integers. * * @param matrix A matrix of integers whose mean is to be computed. * @return Mean value of the matrix. */ public static double mean(int[][] matrix) { int width = matrix.length; int height = matrix[0].length; double sum = 0; for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { sum += matrix[j][i]; } } double mean = sum / (width * height); return mean; } /** * Computes the mean value of a matrix of doubles. * * @param matrix Matrix of doubles whose mean is to be computed. * @return Mean value of the matrix. */ public static double mean(double[][] matrix) { int width = matrix.length; int height = matrix[0].length; double sum = 0; for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { sum += matrix[j][i]; } } double mean = sum / (width * height); return mean; } /** * Computes the mean value of a matrix of longs. * * @param matrix Matrix of longs whose mean is to be computed. * @return Mean value of the matrix. */ public static double mean(long[][] matrix) { int width = matrix.length; int height = matrix[0].length; double sum = 0; for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { sum += matrix[j][i]; } } double mean = sum / (width * height); return mean; } /** * Computes the mean value of a matrix of floats. * * @param matrix Matrix of floats whose mean is to be computed. * @return Mean value of the matrix. */ public static float mean(float[][] matrix) { int width = matrix.length; int height = matrix[0].length; double sum = 0; for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { sum += matrix[j][i]; } } float mean = (float) (sum / (width * height)); return mean; } /** * Computes the mean value of a matrix of bytes. * * @param matrix Matrix of bytes whose mean is to be computed. * @return Mean value of the matrix. */ public static float mean(byte[][] matrix) { int width = matrix.length; int height = matrix[0].length; double sum = 0; for (int j = 0; j < width; j++) { for (int i = 0; i < height; i++) { sum += matrix[j][i]; } } float mean = (float) (sum / (width * height)); return mean; } /** * Computes the mean value of an array of integers. * * @param array Array of integers whose mean is to be computed. * @return Mean value of the array. */ public static double mean(int[] array) { double sum = 0; for (int i = 0; i < array.length; i++) { sum += array[i]; } double mean = sum / array.length; return mean; } /** * Computes the mean value of an array of doubles. * * @param array Array of doubles whose mean is to be computed. * @return Mean value of the array. */ public static double mean(double[] array) { double sum = 0; for (int i = 0; i < array.length; i++) { sum += array[i]; } double mean = sum / array.length; return mean; } /** * Computes the mean value of an array of longs. * * @param array Array of longs whose mean is to be computed. * @return Mean value of the array. */ public static double mean(long[] array) { double sum = 0; for (int i = 0; i < array.length; i++) { sum += array[i]; } double mean = sum / array.length; return mean; } /** * Computes the mean value of an array of floats. * * @param array Array of floats whose mean is to be computed. * @return Mean value of the array. */ public static double mean(float[] array) { double sum = 0; for (int i = 0; i < array.length; i++) { sum += array[i]; } double mean = sum / array.length; return mean; } /** * Computes the mean value of an array of bytes. * * @param array Array of bytes whose mean is to be computed. * @return Mean value of the array. */ public static double mean(byte[] array) { double sum = 0; for (int i = 0; i < array.length; i++) { sum += array[i]; } double mean = sum / array.length; return mean; } }