`
53873039oycg
  • 浏览: 825084 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

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

    博客分类:
  • java
 
阅读更多

      

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]);
		}
	}

  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics