Problem Statement
You have several cards, each with a number printed on them, given in
What is the probability that the value is prime?
Definition
- Class:
- TwoCardsDraw
- Method:
- primeChance
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double primeChance(int[] cards)
- (be sure your method is public)
Notes
- No leading zeroes are added when concatenating the numbers.
Constraints
- cards will contain between 1 and 50 elements, inclusive.
- Each element of cards will be between 1 and 99, inclusive.
Examples
{ 1 }
Returns: 1.0
The only number you're going to get after concatenation is 11, so it's definitely prime.
{ 1, 3 }
Returns: 0.75
11, 13, and 31 are prime, but 33 is not.
{ 2, 4 }
Returns: 0.0
No number you get will be prime.
{ 11, 12, 13 }
Returns: 0.1111111111111111
{ 1, 1, 3 }
Returns: 0.8888888888888888
Notice that numbers can be repeated.
{1, 1, 3, 9, 20, 1, 7, 22, 39, 4, 50, 20, 30, 40, 99, 45 }
Returns: 0.2578125
{3, 10, 23, 3, 4, 5, 2, 1, 2, 2, 10, 23, 1 }
Returns: 0.2603550295857988
{1, 1, 3, 9, 20, 1, 7, 22, 39, 4, 50, 20, 30, 40, 99, 45, 32, 21, 23, 43, 5, 43, 32, 32, 12, 32, 43, 32, 43, 32, 21, 43, 54, 32, 32, 32, 43, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 6, 7 }
Returns: 0.1704