16.1 扑克牌



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);
					}
		}
	 

	
	
	
	
}
	

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值