Java language implementation of simple shuffle, licensing

Source: Internet
Author: User
Tags shuffle

In the course of Java learning, the teacher has written a simple bucket landlord shuffle licensing program, which is the program code:

 Packagecom.java.lei.homework;Importjava.util.Arrays;ImportJava.util.Random; Public classPokergame {//1. Create an array to store poker    Staticstring[] Pokers =Newstring[54];  Public Static voidMain (string[] args) {//2. Create a card with all the cards assigned to the arrayPokers =Newpoker (); //3. Shuffle here the argument pokers is a newly generated pokers after creating the cardstring[] Pokers2 =Upsetpoker (pokers); //4. LicensingSendpoker (pokers2);} //How to create a card     Public Staticstring[] Newpoker () {//1. Define a suit arraystring[] colors = {"Red peach", "spades", "Plum Blossom", "square piece"}; //2. Define the face arraystring[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"}; //3. Define the KingString[] Kings = {"King", "Xiao Wang"}; //4. Using loops to store cards in the pokers array               intindex = 0;  for(inti = 0; i < numbers.length; i + +) {             for(intj = 0; J < Colors.length; J + +) {Pokers[index+ +] = Colors[j] +Numbers[i]; }        }                //5. Size King copy into Pokers arraySystem.arraycopy (Kings, 0, Pokers, index, 2); //6. Output CardSystem.out.println ("Existing deck of Cards" + arrays.tostring (pokers) + "\ n"); returnpokers; }        //Shuffle The way     Public Staticstring[] Upsetpoker (string[] array) {//1. Define a new array to store the washed cardsstring[] Newpokers =NewString[pokers.length]; //2. Define an array to identify the cards that are randomly removed        Boolean[] Mark =New Boolean[Pokers.length]; //3. Shuffle         for(inti = 0; i < pokers.length; i + +) {            //A. Creating a random numberRandom rd =NewRandom (); //B. Obtaining a subscript for a random number            intindex =Rd.nextint (pokers.length); //C. Judging the identity            if(Mark[index] = =false) {                //D. Store the non-washed cards in newpokersNewpokers[i] =Pokers[index]; //E. Modify the logo, the washed card is marked true}Else{i--;//the random number to fetch is a washed card, then re-fetch once            }        }                //copy of the card inside the newpokers to the array pokersPokers =arrays.copyof (Newpokers, newpokers.length); System.out.println ("Washed cards:" + arrays.tostring (newpokers) + "\ n"); returnnewpokers; }        //the method of licensing     Public Static voidSendpoker (string[] array) {//1. Define the player and hole cards arraystring[] One =NewString[0]; String[]=NewString[0]; String[] Three=NewString[0]; String[] Underpoker=NewString[3]; //2. Cycle for Licensing         for(inti = 0; i < pokers.length-3; i++) {            if(i% 3 = = 0) { One= Arrays.copyof (One, one.length+1); One[one.length-1] =Pokers[i]; }Else if(i% 3 = = 1) {= Arrays.copyof (both, two.length+1); Two[two.length-1] =Pokers[i]; }Else if(i% 3 = = 2) {Three= Arrays.copyof (Three, three.length+1); Three[three.length-1] =Pokers[i]; }} system.arraycopy (Pokers, Pokers.length-3, Underpoker, 0, 3); System.out.println ("Player 1:" +arrays.tostring (one)); System.out.println ("Player 2:" +arrays.tostring (both)); System.out.println ("Player 3:" +arrays.tostring (three)); System.out.println ("Hole Card:" +arrays.tostring (Underpoker)); }}

Java language implementation of simple shuffle, licensing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.