當前位置:首頁 » 編程語言 » 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 + "]";
}

}
//本質還是隨機數

熱點內容
sql能力 發布:2025-02-09 10:43:50 瀏覽:981
編譯framework 發布:2025-02-09 10:42:11 瀏覽:380
五子棋對戰演算法 發布:2025-02-09 10:12:19 瀏覽:712
php樹菜單 發布:2025-02-09 10:04:10 瀏覽:359
linux保存ip 發布:2025-02-09 10:04:10 瀏覽:23
四川霜狼伺服器怎麼樣 發布:2025-02-09 10:02:44 瀏覽:145
Vs中h編譯選項是灰的 發布:2025-02-09 10:01:59 瀏覽:557
安卓43怎麼升級44 發布:2025-02-09 09:51:33 瀏覽:463
美國雲伺服器快還是香港快 發布:2025-02-09 09:34:33 瀏覽:988
怎麼解壓qq文件 發布:2025-02-09 09:18:14 瀏覽:581