import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;
import java.util.Scanner;
class Poker
{
String number;
String color;
Poker(String number,String color)
{
this.color = color;
this.number = number;
}
public String toString()
{
return number+" "+color;
}
}
public class wu
{
public static void main(String [] args)
{
Scanner scanner = new Scanner(System.in);
LinkedList li = new LinkedList();
createPoker(li);
shuffPocker(li);
System.out.println("--------------------------");
showPoker(li);
}
//洗牌
public static void shuffPocker(LinkedList li) {
Random ran = new Random();
for(int c =0;c<100;c++)
{
int index1= ran.nextInt(li.size());
int index2= ran.nextInt(li.size());
Poker Poker1 = (Poker)li.get(index1);
Poker Poker2 = (Poker)li.get(index2);
li.set(index1, Poker2);
li.set(index2, Poker1);
}
}
//生成扑克牌
public static void createPoker(LinkedList li) {
String [] number={"2","3","4","5","6","7","8","9","10","J","Q","K","A"};
String [] color={"红桃","方块","黑桃","梅花"};
Random ran= new Random();
for(int i=0;i<number.length;i++)
for(int j=0;j<color.length;j++)
{
li.add(new Poker(number[i],color[j]));
}
}
//显示扑克牌
public static void showPoker(LinkedList li) {
int tt = li.size();
for(int t=0;t<tt;t++)
{
System.out.println(li.pop()+" "+t);
}
}
}
16.1 扑克牌
最新推荐文章于 2023-04-23 22:59:57 发布