Java计算上下基线
public class GetAverageandStandardDevition { static List<Long> list = new ArrayList<Long>(); static { list.add(3210981L); // 1 list.add(3210881L); // 2 list.add(3210781L); // 3 list.add(3210681L); // 4 list.add(3210581L); list.add(3210481L); list.add(3210381L); list.add(3210281L); list.add(3210181L); list.add(3210081L); list.add(3219981L); list.add(3218981L); list.add(3217981L); list.add(3216981L); list.add(3215981L); list.add(3214981L); list.add(3213981L); list.add(3212981L); list.add(3211981L); list.add(3220981L); list.add(3230981L); list.add(3240981L); list.add(3250981L); list.add(3260981L); list.add(3270981L); list.add(3280981L); list.add(3290981L); list.add(3210982L); list.add(3210983L); list.add(3210984L); list.add(3210985L); list.add(3210986L); list.add(3210987L); list.add(3210988L); list.add(3110989L); list.add(3210981L); list.add(3310981L); list.add(3410981L); list.add(2510981L); } // 獲取平均值 public double getAverage() { int sum = 0; for (int i = 0; i < list.size(); i++) { sum += list.get(i); } return (double) (sum / list.size()); } // 獲取標準差 public double getStandardDevition() { double sum = 0; for (int i = 0; i < list.size(); i++) { sum += ((double) list.get(i) - getAverage()) * (list.get(i) - getAverage()); } return Math.sqrt(sum / (list.size() - 1)); } public static void main(String[] args) { GetAverageandStandardDevition gcs = new GetAverageandStandardDevition(); System.out.println(gcs.getAverage()); System.out.println(gcs.getStandardDevition()); // upbase:3451726.682809466,downbase:2965000.3698221124 // 上基线 System.out .println(gcs.getAverage() + 1.960 * gcs.getStandardDevition()); // 下极限 System.out .println(gcs.getAverage() - 1.960 * gcs.getStandardDevition()); } }