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

}
//本質還是隨機數

熱點內容
vs連sql資料庫 發布:2025-07-04 03:55:49 瀏覽:522
樂橙如何提供密碼 發布:2025-07-04 03:55:11 瀏覽:134
榮耀伺服器地址是什麼 發布:2025-07-04 03:55:04 瀏覽:319
手機網頁連接不上伺服器如何解決 發布:2025-07-04 03:29:57 瀏覽:921
計算機多級存儲系統 發布:2025-07-04 03:24:22 瀏覽:283
流控搭腳本 發布:2025-07-04 03:05:59 瀏覽:112
編程的引號 發布:2025-07-04 03:01:09 瀏覽:788
百度雲不能上傳文件 發布:2025-07-04 02:59:28 瀏覽:666
皇冠哪個配置上駕駛座前後移動 發布:2025-07-04 02:45:56 瀏覽:92
安卓沒銀行卡怎麼充值 發布:2025-07-04 02:40:13 瀏覽:668