当前位置:首页 » 编程语言 » 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 + "]";
}

}
//本质还是随机数

热点内容
什么能防止安卓软件自启 发布:2025-09-14 07:48:54 浏览:976
sqlsaserver 发布:2025-09-14 07:44:42 浏览:961
pythonif写一行 发布:2025-09-14 07:41:39 浏览:994
lua存储数据 发布:2025-09-14 07:33:05 浏览:111
教你如何选配置车 发布:2025-09-14 07:32:21 浏览:417
行李箱自带的密码是多少 发布:2025-09-14 07:27:40 浏览:278
ps2020版本怎么调整存储盘 发布:2025-09-14 07:20:28 浏览:860
奥迪a6哪个配置最保值 发布:2025-09-14 07:11:53 浏览:986
android查看文件 发布:2025-09-14 07:00:37 浏览:291
carlyle压缩机 发布:2025-09-14 06:16:51 浏览:978