Write a method with the following header which generates a r
Write a method with the following header which generates a random card by randomly generating integers in the appropriate ranges for the card’s kind and suit. (Note that zero is valid for the suit but not for the kind.) The method should return a reference to an array of integers containing two elements – the first element represents the card’s kind and the second the card’s suit.
public static int[] drawCard()
Solution
Here is the code for you:
import java.util.*;
class DrawCard
{
public static int[] drawCard()
{
Random rnd = new Random();
int kind = rnd.nextInt(13) + 1; //Assuming values from 1 to 13.
int suit = rnd.nextInt(4); //Assuming values from 0 to 3.
int[] array = new int[2];
array[0] = kind;
array[1] = suit;
return array;
}
}
