I am working on a program where need to display the sum of Blackjack with number of instances of 21.

But i am facing some problem here where the string of the ranks is not displayed correctly.

I have marks the fallacy in red as below.

Not sure where is the problem, as it is most correct for most situation

Output:

The number of instances of Blackjack is 1Quote:

Case 1:

picks[i]: 48 :: picks[i] % 13: 9 :: rank: 10 :: picks[i] % 13: 9

picks[i]: 24 :: picks[i] % 13: 11 :: rank: Queen :: picks[i] % 13: 11

The sum of 10 and Queen(10 10) is 20

Case 2:

picks[i]: 48 :: picks[i] % 13: 9 :: rank: 10 :: picks[i] % 13: 9

picks[i]: 21 :: picks[i] % 13: 8 :: rank: 9 :: picks[i] % 13: 8

The sum of 10 and 9(10 9) is 19

Case 3:

picks[i]: 19 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

picks[i]: 50 :: picks[i] % 13: 11 :: rank: Queen :: picks[i] % 13: 11

The sum of 7 and Queen(7 10) is 17

Case 4:

picks[i]: 44 :: picks[i] % 13: 5 :: rank: 6 :: picks[i] % 13: 5

picks[i]: 30 :: picks[i] % 13: 4 :: rank: 5 :: picks[i] % 13: 4

The sum of 6 and 5(6 5) is 11

Case 5:

picks[i]: 34 :: picks[i] % 13: 8 :: rank: 9 :: picks[i] % 13: 8

picks[i]: 4 :: picks[i] % 13: 4 :: rank: 5 :: picks[i] % 13: 4

The sum of 9 and 5(9 5) is 14

Case 6:

picks[i]: 14 :: picks[i] % 13: 1 :: rank: 5 :: picks[i] % 13: 1

picks[i]: 50 :: picks[i] % 13: 11 :: rank: Queen :: picks[i] % 13: 11

The sum of 5 and Queen(2 10) is 12

Case 7:

picks[i]: 29 :: picks[i] % 13: 3 :: rank: 4 :: picks[i] % 13: 3

picks[i]: 23 :: picks[i] % 13: 10 :: rank: Jack :: picks[i] % 13: 10

The sum of 4 and Jack(4 10) is 14

Case 8:

picks[i]: 39 :: picks[i] % 13: 0 :: rank: 4 :: picks[i] % 13: 0

picks[i]: 7 :: picks[i] % 13: 7 :: rank: 8 :: picks[i] % 13: 7

The sum of 4 and 8(11 8) is 19

Case 9:

picks[i]: 37 :: picks[i] % 13: 11 :: rank: Queen :: picks[i] % 13: 11

picks[i]: 33 :: picks[i] % 13: 7 :: rank: 8 :: picks[i] % 13: 7

The sum of Queen and 8(10 8) is 18

Case 10:

picks[i]: 44 :: picks[i] % 13: 5 :: rank: 6 :: picks[i] % 13: 5

picks[i]: 6 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

The sum of 6 and 7(6 7) is 13

Case 11:

picks[i]: 45 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

picks[i]: 41 :: picks[i] % 13: 2 :: rank: 3 :: picks[i] % 13: 2

The sum of 7 and 3(7 3) is 10

Case 12:

picks[i]: 19 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

picks[i]: 49 :: picks[i] % 13: 10 :: rank: Jack :: picks[i] % 13: 10

The sum of 7 and Jack(7 10) is 17

Case 13:

picks[i]: 13 :: picks[i] % 13: 0 :: rank: 7 :: picks[i] % 13: 0

picks[i]: 24 :: picks[i] % 13: 11 :: rank: Queen :: picks[i] % 13: 11

The sum of 7 and Queen(11 10) is 21

Case 14:

picks[i]: 10 :: picks[i] % 13: 10 :: rank: Jack :: picks[i] % 13: 10

picks[i]: 47 :: picks[i] % 13: 8 :: rank: 9 :: picks[i] % 13: 8

The sum of Jack and 9(10 9) is 19

Case 15:

picks[i]: 5 :: picks[i] % 13: 5 :: rank: 6 :: picks[i] % 13: 5

picks[i]: 8 :: picks[i] % 13: 8 :: rank: 9 :: picks[i] % 13: 8

The sum of 6 and 9(6 9) is 15

Case 16:

picks[i]: 21 :: picks[i] % 13: 8 :: rank: 9 :: picks[i] % 13: 8

picks[i]: 9 :: picks[i] % 13: 9 :: rank: 10 :: picks[i] % 13: 9

The sum of 9 and 10(9 10) is 19

Case 17:

picks[i]: 14 :: picks[i] % 13: 1 :: rank: 10 :: picks[i] % 13: 1

picks[i]: 3 :: picks[i] % 13: 3 :: rank: 4 :: picks[i] % 13: 3

The sum of 10 and 4(2 4) is 6

Case 18:

picks[i]: 13 :: picks[i] % 13: 0 :: rank: 10 :: picks[i] % 13: 0

picks[i]: 40 :: picks[i] % 13: 1 :: rank: 4 :: picks[i] % 13: 1

The sum of 10 and 4(11 2) is 13

Case 19:

picks[i]: 6 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

picks[i]: 49 :: picks[i] % 13: 10 :: rank: Jack :: picks[i] % 13: 10

The sum of 7 and Jack(7 10) is 17

Case 20:

picks[i]: 19 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

picks[i]: 32 :: picks[i] % 13: 6 :: rank: 7 :: picks[i] % 13: 6

The sum of 7 and 7(7 7) is 14

Code:`public static void main(String[] args) {`

Scanner input = new Scanner(System.in);

final int NO_OF_PICKS = 2;

int count = 0;

int[] picks = new int[NO_OF_PICKS];

String[] ranks = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};

for(int i = 0; i < 20; i++){

System.out.print("Case " + (i + 1) + ": " );

if(isBlackJack(ranks,picks)){

count++;

}

}

System.out.println("The number of instances of Blackjack is " + count);

}

public static boolean isBlackJack(String[] ranks, int[] picks){

int[] valueOfPicks = new int[picks.length];

final int NO_OF_CARDS = 52;

for(int i = 0; i < picks.length; i++){

picks[i] = (int)(Math.random() * NO_OF_CARDS);

System.out.print("\n" + "picks[i]: " + picks[i] + " :: ");

ranks[i] = ranks[picks[i] % 13];

System.out.print("picks[i] % 13: " + picks[i] % 13 + " :: ");

System.out.print("rank: " + ranks[i] + " :: ");

valueOfPicks[i] = returnValue(picks[i] % 13);

System.out.print("picks[i] % 13: " + picks[i] % 13 + " " );

}

System.out.println();

int sum = valueOfPicks[0] + valueOfPicks[1];

System.out.print("The sum of " + ranks[0] + " and " + ranks[1]);

System.out.print("(" + valueOfPicks[0] + " " + valueOfPicks[1] + ")");

System.out.println(" is " + sum);

System.out.println();

if(sum == 21){

return true;

}

return false;

}

public static int returnValue(int i){

if(i == 0){

return 11;

}

else if(i >= 1 && i <= 9){

return i + 1;

}

return 10;

}