dimanche 5 mai 2019

How to use loop to generate random strings until certain criteria achieved? [duplicate]

This question already has an answer here:

I'm trying to create two string arrays randomiser that will loop until both of the arrays reach same output.

I've tried the code below, but the output didn't randomise:

    int suitRandom = gen.nextInt(4);
    int valueRandom = gen.nextInt(13);
    String Card1 = arrayValue[valueRandom] + arraySuit[suitRandom];

    int suitRandom2 = gen.nextInt(4);
    int valueRandom2 = gen.nextInt(13);
    String Card2 = arrayValue[valueRandom2] + arraySuit[suitRandom2];

    while (Card1 != Card2){
    System.out.println("Card 1: " + Card1);
    System.out.println("Card 2: " + Card2);
        if (Card1 == Card2){
        System.out.println("Win");
        }
        else{
        System.out.println("Lose");
        }

I expect that the loop will generate random output and until the output of Card1 equal to Card2.

Can somebody please help? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire