java双精度数组定义,Java 计算一个双精度数组的和。

//package com.nowjava;

import java.util.List;//from n o w j a v a . c o m

public class Main {

public static void main(String[] argv) throws Exception {

double[] array = new double[] { 34.45, 35.45, 36.67, 37.78,

37.0000, 37.1234, 67.2344, 68.34534, 69.87700 };

System.out.println(sum(array));

}

/**

* Computes the sum of an array of doubles.

*

* @param array Array of doubles to be added up.

* @return Sum of the array.

*/

public static double sum(double[] array) {/**from n o w j a v a . c o m - 时 代 Java**/

double sum = 0;

for (double d : array) {

sum += d;

}

return sum;

}

/**

* Computes the sum of an array of integers.

*

* @param array Array of integers to be added up.

* @return Sum of the array.

*/

public static int sum(int[] array) {

int sum = 0;

for (int i : array) {

sum += i;

}

return sum;

}

/**

* Computes the sum of an array of floats.

*

* @param array Array of floats to be added up.

* @return Sum of the array.

*/

public static float sum(float[] array) {

int sum = 0;

for (float f : array) {

sum += f;

}

return sum;

}

/**

* Computes the sum of an array of longs.

*

* @param array Array of longs to be added up.

* @return Sum of the array.

*/

public static long sum(long[] array) {

long sum = 0;

for (long l : array) {

sum += l;

}

return sum;

}

/**

* Computes the sum of an array of bytes.

*

* @param array Array of bytes to be added up.

* @return Sum of the array.

*/

public static int sum(byte[] array) {

int sum = 0;

for (byte b : array) {

sum += b;

}

return sum;

}

/**

* Computes the sum of values in a matrix of integers.

*

* @param matrix Matrix of integers.

* @return Sum of the matrix values.

*/

public static int sum(int[][] matrix) {

int width = matrix.length;

int height = matrix[0].length;

int sum = 0;

for (int j = 0; j < width; j++) {

for (int i = 0; i < height; i++) {

sum += matrix[j][i];

}

}

return sum;

}

/**

* Computes the sum of values in a matrix of doubles.

*

* @param matrix Matrix of doubles.

* @return Sum of the matrix values.

*/

public static double sum(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];

}

}

return sum;

}

/**

* Computes the sum of values in a matrix of longs.

*

* @param matrix Matrix of longs.

* @return Sum of the matrix values.

*/

public static long sum(long[][] matrix) {

int width = matrix.length;

int height = matrix[0].length;

long sum = 0;

for (int j = 0; j < width; j++) {

for (int i = 0; i < height; i++) {

sum += matrix[j][i];

}

}

return sum;

}

/**

* Computes the sum of values in a matrix of floats.

*

* @param matrix Matrix of floats.

* @return Sum of the matrix values.

*/

public static float sum(float[][] matrix) {

int width = matrix.length;

int height = matrix[0].length;

float sum = 0;

for (int j = 0; j < width; j++) {

for (int i = 0; i < height; i++) {

sum += matrix[j][i];

}

}

return sum;

}

/**

/**代码未完, 请加载全部代码(NowJava.com).**/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值