Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the game of fighting landlords with ArrayList+Collections

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to realize the game of fighting landlords in ArrayList+Collections". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to fight landlords in ArrayList+Collections"!

A deck of poker has 54 cards: big and small Wang + 4x13. Next, let's simulate the dealing process of fighting landlords.

First of all, we need to buy cards, the newly bought cards are placed in order, so the next step is to shuffle, and finally is to deal, but when dealing, we should pay attention to leave three cards at the end.

The main classes used are ArrayList: to store cards and Collections to shuffle cards.

Import java.util.ArrayList

Import java.util.Collections

/ *

* A total of 54 cards are issued by simulated landlords.

* buying cards

* shuffle

* Licensing

*

, /

Public class DouDIZhuDemo {

Public static void main (String [] args) {

/ / pattern array

String [] arr = {"spades", "hearts", "clubs", "square"}

String [] arr2 = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}

/ / buying cards

ArrayList box = new ArrayList ()

/ / add cards

/ / get design and color

For (int I = 0; I < arr.length; iTunes +)

/ / get the value

For (int j = 0; j < arr2.length; jacks +)

Box.add (ARR [I] + arr2 [j])

/ / Big and small King

Box.add ("King")

Box.add (Xiao Wang)

/ / shuffle

Collections.shuffle (box)

/ / deal three cards to the landlord, leaving 51 cards, 17 cards each

/ / three players who play cards

ArrayList Qibao = new ArrayList ()

ArrayList Babao = new ArrayList ()

ArrayList Nine Treasures = new ArrayList ()

For (int I = 0; I < box.size ()-3; iTunes +) {

If (I% 3 percent 0)

Add (box.get (I))

Else if (I% 3 percent 1)

Add (box.get (I))

Else if (I% 3 percent 2)

Add (box.get (I))

}

System.out.println ("Qibao:" + Qibao)

System.out.println ("Babao:" + Babao)

System.out.println ("Jiubao:" + Jiubao)

/ / bottom card

For (int i=box.size ()-3TX I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report