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

}
//本质还是随机数

热点内容
怎么解压qq文件 发布:2025-02-09 09:18:14 浏览:580
安卓最新怎么调灵敏度更稳 发布:2025-02-09 09:12:44 浏览:399
豌豆荚如何用安卓手机下载 发布:2025-02-09 09:11:57 浏览:212
吃鸡脚本辅助 发布:2025-02-09 09:09:29 浏览:5
sessionidpython 发布:2025-02-09 09:08:53 浏览:275
华为手机验证码和密码忘了是多少 发布:2025-02-09 08:53:53 浏览:798
逆战笔记哪个配置好玩 发布:2025-02-09 08:53:04 浏览:599
怎么打开电脑云服务器 发布:2025-02-09 08:36:01 浏览:219
日元对人民币算法 发布:2025-02-09 08:35:52 浏览:39
安卓手机微信语音怎么不能转文 发布:2025-02-09 08:25:30 浏览:922