Java Array Sum sum(double[] d)

Here you can find the source of sum(double[] d)

Description

sum

License

Open Source License

Declaration

public static double sum(double[] d) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double sum(double[] d) {
        double ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];//  w  w w. j  av a  2 s  .  com
        }
        return ret;
    }

    public static double sum(double[][] d) {
        double ret = 0;
        for (int i = 0; i < d.length; i++) {
            for (int j = 0; j < d[0].length; j++) {
                ret += d[i][j];
            }
        }
        return ret;
    }

    public static double sum(double[] d, int n) {
        double ret = 0;
        for (int i = 0; i < n; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static int sum(int[] d) {
        int ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static float sum(float[] d) {
        float ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static long sum(long[] d) {
        long ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }
}

Related

  1. sum(double[] array)
  2. sum(double[] array)
  3. sum(Double[] array)
  4. sum(double[] array)
  5. sum(double[] array)
  6. sum(double[] data)
  7. sum(double[] data)
  8. sum(double[] data, int i_, int n_)
  9. sum(double[] dbs)