-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDeckOfCards.java
More file actions
executable file
·36 lines (34 loc) · 1.19 KB
/
DeckOfCards.java
File metadata and controls
executable file
·36 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* */ package ch07;
/* */
/* */ public class DeckOfCards {
/* */ public static void main(String[] args) {
/* 5 */ int[] deck = new int[52];
/* 6 */ String[] suits = { "Spades", "Hearts", "Diamonds", "Clubs" };
/* 7 */ String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
/* */
/* */ int i;
/* */
/* 11 */ for (i = 0; i < deck.length; i++) {
/* 12 */ deck[i] = i;
/* */ }
/* */
/* 15 */ for (i = 0; i < deck.length; i++) {
/* */
/* 17 */ int index = (int)(Math.random() * deck.length);
/* 18 */ int temp = deck[i];
/* 19 */ deck[i] = deck[index];
/* 20 */ deck[index] = temp;
/* */ }
/* */
/* */
/* 24 */ for (i = 0; i < 4; i++) {
/* 25 */ String suit = suits[deck[i] / 13];
/* 26 */ String rank = ranks[deck[i] % 13];
/* 27 */ System.out.println("Card number " + deck[i] + ": " + rank + " of " + suit);
/* */ }
/* */ }
/* */ }
/* Location: /Volumes/TXS.128G/hope useful/practice/2020.jar!/ch07/DeckOfCards.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/