当前位置:首页 » 编程语言 » 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-17 23:45:44 浏览:902
c语言编小游戏 发布:2025-09-17 23:33:46 浏览:407
法哪科编程 发布:2025-09-17 23:20:03 浏览:570
摩斯密码怎么敲汉字 发布:2025-09-17 23:11:05 浏览:361
标记c语言 发布:2025-09-17 22:28:38 浏览:593
编译原理语义检查 发布:2025-09-17 22:26:07 浏览:662
uint哪个配置有行车记录仪 发布:2025-09-17 22:15:38 浏览:431
设计php框架 发布:2025-09-17 21:50:05 浏览:180
sql统计条数 发布:2025-09-17 21:49:51 浏览:712
javastatic和 发布:2025-09-17 21:35:35 浏览:369