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