Java code help. Error within code

Case “2” contains a break before the if statement, which will make it unreachable.

Having one break at the end of your case will make the if statement run.

case "2":
    for (int i = 0; i < g; i++) 
    {   
        blackjack = rand.nextInt((21 - 1) + 1);
        System.out.print(blackjack);
        dealer -= player;
    }

    System.out.println("");
    System.out.println("Player wins");

    if (dealer >= player) {
        System.out.println("Dealer wins!" +blackjack+ ".");
    } else (dealer <= player) {
        System.out.println("Player wins" +won+ " dollars!");
    }
    break;
}

Leave a Comment