當前位置:首頁 » 編程語言 » 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-05-13 19:00:08 瀏覽:724
c語言負數運算 發布:2025-05-13 18:45:21 瀏覽:428
太空殺電腦版連接不到伺服器 發布:2025-05-13 18:40:19 瀏覽:457
同樣的配置為什麼跑分不同 發布:2025-05-13 18:39:06 瀏覽:278
獲取linuxcpu序列號 發布:2025-05-13 18:36:35 瀏覽:738
appleid為什麼連接伺服器出現問題 發布:2025-05-13 18:17:37 瀏覽:971
書翁怎麼配置 發布:2025-05-13 18:17:36 瀏覽:911
雲資料庫mongodb 發布:2025-05-13 18:16:12 瀏覽:774
A7編程 發布:2025-05-13 18:15:26 瀏覽:742
python視圖 發布:2025-05-13 18:14:01 瀏覽:759