G**7 发帖数: 391 | 1 To keep my status, I have to go back to school. I am not a computer major.
However, one of the classes I am taking is Java. The professor asks us to
write a program to shuffle a deck of cards.
Can anyone tell me the Java code for shuffling a deck of cards? or tell
me where to find such websites or solutions? I have done numerous internet
solutions, but didn't find any codes working.
Would appreciate if anyone can help. You can also send emails to me. | d**e 发帖数: 6098 | 2 前两天才讨论过
http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
tell
【在 G**7 的大作中提到】 : To keep my status, I have to go back to school. I am not a computer major. : However, one of the classes I am taking is Java. The professor asks us to : write a program to shuffle a deck of cards. : Can anyone tell me the Java code for shuffling a deck of cards? or tell : me where to find such websites or solutions? I have done numerous internet : solutions, but didn't find any codes working. : Would appreciate if anyone can help. You can also send emails to me.
| y***y 发帖数: 224 | 3 void randint(){
Random r = new Random();
int temp=0;
int index=0;
int[] a = new int[52];
for(int i=0;i
a[i]=i;
for(int i=0;i
index=r.nextInt(52-i)+i;
temp=a[i];
a[i]=a[index];
a[index]=temp;
}
for(int i=0;i
System.out.print(a[i]+" ");
} |
|