Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program that generates 5 random integers in the range 0-51. Each of

ID: 3886812 • Letter: W

Question

Write a Java program that generates 5 random integers in the range 0-51. Each of these values will represent playing card. Print a text description of each card using the following rules (as discussed in class). Cards 0-12 are Diamonds. Cards 13-25 are Hearts. Cards 26-38 are Spades. Cards 39-51 are Clubs. Card 0 is an Ace. Card 1 is a Two. Card 2 is a Three and so on. Card 10 is a Jack. Card 11 is a Queen. Card 12 is a King. Example output of your program will look something like: Queen of Hearts Two of Diamonds Three of Diamonds Eight of Clubs Five of Spades

Explanation / Answer

//for generating random cards

package javaplayingcard;
import java.util.*;

public class Javaplayingcard {

public static void main(String[] args) {
// Initializing array of cards
String[] card = {"ACE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE","TEN","JACK","QUEEN","KING"};
//Initializing array of catagory
String[] suit = {"DIAMONDS","HEARTS","SPADE","CLUB"};
int i;//variable for loop
int a[] = new int[5];//array for storing random numbers
Random r = new Random();//generating random numbers
//storing random numbers and print the selected cards
for(i = 0; i<5; i++){
a[i]=r.nextInt(52)-1;
System.out.println(card[(a[i]%13)]+" of " + suit[(a[i]/13)]);
}
}
  
}

sample output :

run:
FOUR of HEARTS
NINE of SPADE
NINE of SPADE
THREE of HEARTS
EIGHT of SPADE
BUILD SUCCESSFUL (total time: 0 seconds)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote