This article describes the method of generating 52 poker by simulated poker cards and reshuffle. Share it for your reference, as follows:
Require:
Generate 52 poker pictures, simulate playing cards shuffle, and output.
Implementation code:
package com.NCU.ZHANGhuirong;import java.util.ArrayList;import java.util.Collections;public class Card { public String poker(int num) { String str = ""; String[] face = { "♥", "♠", "♣", "♦" }; String[] number = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; str += face[num % 4] + number[num % 13]; return str; } public void shuffle(@SuppressWarnings("rawtypes") ArrayList list) { } @SuppressWarnings("unchecked") public static void main(String[] args) { @SuppressWarnings("rawtypes") ArrayList list = new ArrayList(); Card card = new Card(); for (int i = 0; i < 52; i++) { list.add(card.poker(i)); } for (int i = 0; i < 52; i++) { list.add(card.poker(i)); } for (int i = 0; i < list.size(); i++) { System.out.printf("%s/t", list.get(i)); if ((i + 1) % 13 == 0) { System.out.println(" "); } } System.out.println(); Collections.shuffle(list); System.out.println("Shushed:"); for (int i = 0; i < list.size(); i++) { System.out.printf("%s/t", list.get(i)); if ((i + 1) % 13 == 0) { System.out.println(" "); } } }}Output:
♥A ♠2 ♣3 ♦4 ♥5 ♣6 ♣7 ♣8 ♥9 ♠10 ♣J ♦Q ♥K ♠A ♣2 ♦3 ♥4 ♣5 ♣6 ♦7 ♥8 ♠9 ♣10 ♦J ♥Q ♣K ♣A ♣2 ♣3 ♣4 ♣5 ♣6 ♣7 ♣8 ♦9 ♥10 ♠J ♣Q ♣K ♣A ♣2 ♣3 ♣4 ♣5 ♣6 ♣8 ♦9 ♥10 ♠J ♣Q ♣K K After shuffling: ♥3 ♥9 ♦6 ♥J ♦K ♥4 ♣8 ♥K ♦Q ♣5 ♣7 ♠J ♠A ♣10 ♣A ♥8 ♠9 ♥Q ♦4 ♠6 ♠8 ♥10 ♣2 ♣10 ♦7 ♠10 ♥A ♣J ♠K ♠5 ♥2 ♣8 ♦J ♠Q ♦3 ♦9 ♣Q ♣K ♣3 ♥5 ♣6 ♣5 ♣2 ♦A ♥7 ♠4 ♥6 ♠7 ♣4 ♠3 ♠2 ♣9
For more information about Java algorithms, readers who are interested in this site can view the topics: "Java Data Structure and Algorithm Tutorial", "Summary of Java Operation DOM Node Tips", "Summary of Java File and Directory Operation Tips" and "Summary of Java Cache Operation Tips"
I hope this article will be helpful to everyone's Java programming.