Question: There are 100 people in the room, each of them has 100 yuan, and they are playing a game. In each round of the game, everyone has to give one dollar to another person randomly. What is the wealth distribution of these 100 people in the end? Guess, after 10,000 exchanges, what do you think the final result will be like?
The answer is like this.
In fact, many people did not expect the result to be like this at the beginning.
We use Java GUI to visually understand this problem.
First initialize the data. At the beginning, everyone has 100 yuan.
<code> // 初始化数据<br> money = new int[100];<br> for(int i = 0 ; i < money.length ; i ++)<br/> money[i] = 100;</code>
, The above is the detailed content of Java GUI visualization example analysis. For more information, please follow other related articles on the PHP Chinese website!<code> for(int i = 0 ; i < money.length; i ++){<br/> if(money[i] > 0){<br> int j = (int)(Math.random() * money.length);<br> money[i] -= 1;<br> money[j] += 1;<br> }<br> }<br></code>
<code>Arrays.sort(money);<br>for(int i = 0 ; i < money.length; i ++){<br/> if(money[i] > 0){<br> int j = (int)(Math.random() * money.length);<br> money[i] -= 1;<br> money[j] += 1;<br> }<br> }</code>