Hunter的大杂烩 技术学习笔记

2012-07-06

Excel中的部分统计函数 的Java实现

Filed under: 技术话题 — hunter @ 7:11 pm

部分参考: http://blog.csdn.net/peakryuu/article/details/6180711

               http://derpvail.iteye.com/blog/260992

不过两个出处都有些小bug,经过修正后如下:
public class StatisticalFunction {
 public static double max(double[] p){
  if (p.length == 0)
   throw new IllegalArgumentException();
  int len = p.length;
  double max = p[0];
  for (int i = 0; i < len; i++) {    if (max < p[i])     max = p[i];   }   return max;  }
 public static double min(double[] p){
  if (p.length == 0)
   throw new IllegalArgumentException();
  int len = p.length;
  double min = p[0];
  for (int i = 0; i < len; i++) {    if (min > p[i])
    min = p[i];
  }
  return min;
 }
 public static double sum(double[] p){
  if (p.length == 0)
   return 0;
  int len = p.length;
  double sum = 0;
  for (int i = 0; i < len; i++) {    sum += p[i];   }   return sum;  }  public static double avg(double[] p) {      double sumV = 0;  // sum of all the elements   if (p.length == 0)    return sumV;      sumV = sum(p);      return sumV / p.length;  }  public static double square_sum(double[] p) {   int len = p.length;   double sqrsum = 0.0;   for (int i = 0; i www.hunterpro.net

 

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress