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

}
//本质还是随机数

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:556
制作脚本网站 发布:2025-10-20 08:17:34 浏览:840
python中的init方法 发布:2025-10-20 08:17:33 浏览:546
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:721
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:645
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:963
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:217
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:74
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:765
python股票数据获取 发布:2025-10-20 07:39:44 浏览:673