当前位置:首页 » 编程语言 » java概率随机

java概率随机

发布时间: 2023-07-06 00:23:09

A. 求一段JAVA的概率算法

public class Zhuq {
public static void main(String[] args) {
List<Person> listP=new ArrayList<Person>();
listP.add(new Person("小李", "1", 200));
listP.add(new Person("小王", "2", 210));
listP.add(new Person("小赵", "3", 230));
listP.add(new Person("小孙", "4", 100));
listP.add(new Person("小钱", "5", 3));
listP.sort(new Comparator<Person>() {

@Override
public int compare(Person o1, Person o2) {
// TODO Auto-generated method stub
return (((Person)o1).count)*(Math.random()*10+1)>(((Person)o2).count)*(Math.random()*10+1)?-1:1;
}
});
System.out.println(listP);
}
}

class Person {
String personName;
String id;
int count;

public Person(String personName, String id, int count) {
super();
this.personName = personName;
this.id = id;
this.count = count;
}
@Override
public String toString() {
return "Person [personName=" + personName + ", id=" + id + ", count=" + count + "]";
}

}
//本质还是随机数

热点内容
三菱plc一段二段密码什么意思 发布:2025-05-14 21:17:16 浏览:527
电脑开机密码忘记了怎么破解 发布:2025-05-14 21:09:40 浏览:56
pythondict格式 发布:2025-05-14 21:09:38 浏览:885
落叶片拍摄脚本 发布:2025-05-14 20:40:49 浏览:798
安卓为什么不能用cmwap 发布:2025-05-14 20:40:43 浏览:657
jquery获取上传文件 发布:2025-05-14 20:27:57 浏览:44
云web服务器搭建 发布:2025-05-14 20:25:36 浏览:526
汽修汽配源码 发布:2025-05-14 20:08:53 浏览:743
蜜蜂编程官网 发布:2025-05-14 19:59:28 浏览:58
优酷怎么给视频加密 发布:2025-05-14 19:31:34 浏览:635