【问题标题】:How to get percentile in java如何在java中获得百分位数
【发布时间】:2016-04-11 15:51:44
【问题描述】:

我有一个想要获得百分位数的列表。

HashMap<Integer,String> test=new HashMap<Integer,String>();  
test.put(100,"Amit");  
test.put(101,"Vijay");  
test.put(102,"Rahul"); 
test.put(103,"Amit");  
test.put(104,"Vijay");  
test.put(105,"Rahul");

使用以下百分位数公式,我该如何迭代和正确使用? 我想得到哈希图中每个键的百分位数

Number of scores blow X*100/N

【问题讨论】:

  • 不清楚你想要什么?简述
  • 我想得到哈希图中每个键的百分位数

标签: java hashmap percentile


【解决方案1】:

你可以做这样的事情(假设百分位数是指相对于每个人得分的最高分,如果你想要分配,那么你可能想要使用不同的计算,但这应该会给你一个想法)

    int maxScore = 0;
    for ( Integer score : test.keySet()) {
         if (score > maxScore) {
             maxScore = score;
         }
    }
    for ( Integer score : test.keySet()) {

         System.out.print(String.format("%s's percentile %5.2f\n", test.get(score), 
                 ((double)score/(double)maxScore)*100));
    }

使用您拥有的数据,您应该得到如下结果

Rahul's percentile 97.14
Amit's percentile 98.10
Amit's percentile 95.24
Vijay's percentile 96.19
Vijay's percentile 99.05
Rahul's percentile 100.00

【讨论】:

  • 如果我需要基于价值获得?
【解决方案2】:

所以我在 HashMaps 上做了很多工作,但是看看 JavaDoc 应该是这样的

Hashmap<Integer><String> h;
int sum = 0;
for(int i: h.keySet()) {
  sum += i;
}
double percentile = sum/h.size()

【讨论】:

  • 我不想要密钥我无法获得 ech 密钥的百分位数
  • 如果我猜对了,那么就只需要寻找 double perc = 1/h.size();编辑:nvm,生病改变我的答案
猜你喜欢
  • 1970-01-01
  • 2016-04-12
  • 2020-08-08
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 2018-11-21
  • 2021-01-09
  • 1970-01-01
相关资源
最近更新 更多