java generates poker----basic Java Learning Summary

Source: Internet
Author: User

Preface all lazy Write, all 1:30 A.M., directly put the code up code:
1  Packagecom.day16.list;2 3 Importjava.util.LinkedList;4 ImportJava.util.Random;5 6 /**7 * Class Description:8  * 9  * @authorAuthor: ChenyanlongTen  * @versionCreation Date: October 29, 2017 One  */ A  - //Poker Class - classPoker { the  -String color;//Color -String num;//points -  +     //Construction Method -      PublicPoker (string color, string num) { +         Super(); A          This. color =color; at          This. num =num; -     } -  -     //rewrite ToString () - @Override -      PublicString toString () { in         returncolor+num; -     } to  + } -  the  Public classDemo { *      $      Public Static voidMain (string[] args) {Panax Notoginseng         //instantiating a Collection object -LinkedList pockers=Createpoker (); theFlushpockes (pockers);//Shuffle +Showpoker (pockers);//show how many cards A          the     } +      -     //how to generate poker $      Public  StaticLinkedList Createpoker () { $         //This collection is used to store poker objects -LinkedList list=NewLinkedList (); -         //define an array to store all the suits and points theString[] colors={"Black", "Red Peach", "Plum", "block"}; -String[] nums={"A", "2", "3", "4", "5", "6", "7", "8", "9", "Ten", "J", "Q", "K"};Wuyi          the         //add a poker in a collection -          for(inti=0;i<nums.length;i++){ Wu              for(intj=0;j<colors.length;j++){ -List.add (NewPoker (Colors[j],nums[i])); About             } $         } -         returnlist; -     } -      A     //Shuffle the function +      Public Static voidflushpockes (LinkedList pockers) { the        //creating random Objects -Random random=NewRandom (); $          for(inti=0;i<100;i++){ the             //randomly generates two index values the             intA=Random.nextint (Pockers.size ()); the             intb=Random.nextint (Pockers.size ()); the             //remove two cards based on index value -Poker a1=(Poker) Pockers.get (a); inPoker b1=(Poker) pockers.get (b); the Pockers.set (A, B1); the Pockers.set (b, A1); About         } the     } the      the     //Show Poker +      Public Static voidShowpoker (LinkedList pockers) { -          for(intI=0;i<pockers.size (); i++){ theSystem.out.print ("" +Pockers.get (i)); Bayi             //line Break the             if(i%10==9){ the System.out.println (); -             } -         } the System.out.println (); theSystem.out.println ("Number of Cards:" +pockers.size ());//show how many cards the     } the      -}

Operating effect:

java generates poker----basic Java Learning Summary

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.