mercredi 23 mai 2018

Comparing Answers (Not in Array)

How do you tell Java to print the value of matching numbers that are randomly generated. For example, if the output is 3,3,7: the system should print out, "You got two 3's".

    int roll1 = (int) (Math.random()*6) +1;
    int roll2 = (int) (Math.random()*6) +1;
    int roll3 = (int) (Math.random()*6) +1;


    System.out.print("Your numbers are " + roll1 + r2 + r3);

    if (r1 == r2 && r2 ==s3 )
        System.out.print(": You got all" + s1 + "'s");
    else if (r1 == r2 || r2 == r3 || r1 == r3)
        System.out.print(": You got two" + "'s");
    else if (r1 != r2 && sr != r3)
        System.out.print(": NO MATCHES!");
    else {

    }




Aucun commentaire:

Enregistrer un commentaire