Two-dimensional array --- simulate landlords, two-dimensional array --- landlords

Source: Internet
Author: User

Two-dimensional array --- simulate landlords, two-dimensional array --- landlords

Package com. pb. demo; import java. util. Arrays; import java. util. Random;/*** Random poker card Licensing♠♥♣♦Two-dimensional array implementation **/public class Puker {public static void main (String [] args) {// defines the array String [] [] puker = new String [5] []; puker [0] = new String [] {"♠A ","♠2 ","♠3 ","♠4 ","♠5 ","♠6 ","♠7 ","♠8 ","♠9 ","♠10 ","♠J ","♠Q ","♠K "}; puker [1] = new String [] {"♥A ","♥2 ","♥3 ","♥4 ","♥5 ","♥6 ","♥7 ","♥8 ","♥9 ","♥10 ","♥J ","♥Q ","♥K "}; puker [2] = new String [] {"♣A ","♣2 ","♣3 ","♣4 ","♣5 ","♣6 ","♣7 ","♣8 ","♣9 ","♣10 ","♣J ","♣Q ","♣K "}; puker [3] = new String [] {"♦A ","♦2 ","♦3 ","♦4 ","♦5 ","♦6 ","♦7 ","♦8 ","♦9 ","♦10 ","♦J ","♦Q ","♦K "}; puker [4] = new String [] {" "," "}; // define three players and the base card String [] player1 = new String [17]; String [] player2 = new String [17]; string [] player3 = new String [17]; String [] temp = new String [3]; // two-dimensional data shuffling Random random = new Random (); int i1 = 0, i2 = 0, j1 = 0, j2 = 0; // defines four variables to store the subscript of the array. // shuffling 1000 times for (int I = 0; I <1000; I ++) {// subscript i1 equals, random 0 ~ I1 = random. nextInt (5); // 0 ~ Between 4 if (i1 = 4) {// if the subscript of one dimension is 4, the two-dimensional element has only two kings and kings, and only two elements, j1 = random. nextInt (2);} else {// if not 4, there are 13 cards in j1 = random. nextInt (13); // 0 ~ 12 A total of 13 elements} // because the shortest array is two elements, it takes two times. If there are multiple elements, it will take multiple times i2 = random. nextInt (5); if (i2 = 4) {j2 = random. nextInt (2);} else {j2 = random. nextInt (13);} // start shuffling String tmp = puker [i1] [j1]; puker [i1] [j1] = puker [i2] [j2]; // shuffles, exchanges, and disrupts the order of puker [i2] [j2] = tmp;} // The shuffled card System. out. println ("============= the order after shuffling =============="); for (int I = 0; I <puker. length; I ++) {for (int j = 0; j <puker [I]. length; j ++) {System. out. print (puker [I] [j] + "") ;}// start licensing for (int I = 0; I <54; I ++) {int p = I % 3; // defines the player to which int k = I/3-1; // defines the round if (I <3) {// first deduct the three base cards temp [I] = puker [I/13] [I % 13]; // retrieve three from the previous direction, estimate base card} else if (p = 0) {player1 [k] = puker [I/13] [I % 13];} else if (p = 1) {player2 [k] = puker [I/13] [I % 13];} else if (p = 2) {player3 [k] = puker [I/13] [I % 13] ;}} System. out. println ("\ n =========== licensed completion ================"); // player a System. out. println ("Player 1" + Arrays. toString (player1); // PLAYER 2 System. out. println ("Player 2" + Arrays. toString (player2); // Player 3 System. out. println ("Player 3" + Arrays. toString (player3); // card System. out. println ("card" + Arrays. toString (temp ));}}

 

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.