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

}
//本質還是隨機數

熱點內容
d盤無法訪問參數不正確 發布:2025-09-17 06:30:36 瀏覽:466
為什麼徵兵網無法訪問 發布:2025-09-17 06:19:31 瀏覽:373
mysqlsql語句變數賦值 發布:2025-09-17 06:19:26 瀏覽:34
真我3i什麼配置 發布:2025-09-17 06:17:59 瀏覽:138
輸入有效的伺服器地址ip 發布:2025-09-17 06:17:26 瀏覽:437
德育源碼 發布:2025-09-17 06:16:00 瀏覽:103
低價虛擬機ftp伺服器租用公司 發布:2025-09-17 06:14:23 瀏覽:887
戴爾筆記本電腦開機密碼是多少 發布:2025-09-17 06:03:14 瀏覽:444
ac68u外網訪問 發布:2025-09-17 05:33:12 瀏覽:905
真我手機如何修改登錄密碼 發布:2025-09-17 05:20:26 瀏覽:317