当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

[代码片段]数组数据分段统计

发表于: 2015-01-14   作者:53873039oycg   来源:转载   浏览:
摘要:        public void analyseData3(double[] scores, int maxScore, int passScore, int step, boolean mergeBelowPass) { int num = 0, start = 0, end = -1; if (!mergeB

      

public void analyseData3(double[] scores, int maxScore, int passScore,
			int step, boolean mergeBelowPass) {
		int num = 0, start = 0, end = -1;
		if (!mergeBelowPass) {
			num = maxScore / step;
			end = maxScore / step * step;
			start = 0;
		} else {
			num = (maxScore - passScore) / step;
			end = passScore + (maxScore - passScore) / step * step;
			start = passScore - step;
			++num;
		}
		if (end < maxScore) {
			++num;
			end += step;
		}
		List<String> labelList = new ArrayList<String>();
		for (int i = start, j = 1; j <= num; i += step, j++) {
			labelList.add(new String((i == start ? "0" : i) + " ~ "
					+ (j == num ? maxScore : (i + step - 1))));
		}
		int[] numSum = new int[num];
		double exp = 0.00001;
		if (mergeBelowPass) {
			for (double d : scores) {
				if (d < passScore) {
					numSum[0]++;
				} else {
					int index = (int) Math
							.ceil((1.0 * (d - passScore + exp) / step));
					if (index >= num) {
						numSum[num - 1]++;
					} else {
						numSum[index]++;
					}
				}
			}
		} else {
			for (double d : scores) {
				int index = (int) (d / step);
				if (index >= num) {
					numSum[num - 1]++;
				} else {
					numSum[index]++;
				}
			}
		}
		for (int i = 0; i < labelList.size(); i++) {
			System.out.println(labelList.get(i) + "---=" + numSum[i]);
		}
	}

  

 

[代码片段]数组数据分段统计

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号