jeudi 22 septembre 2016

Adding numbers from an if-statement that only follow the requirement

I have this bit of code for an if statement. What I'm trying to do is add all number 3s that appear in a random roll of five die.

For example, I roll: 5 5 2 3 3

6 is meant to print out.

Currently, if a 3 appears, it adds all of the rolls. I'm trying to understand how to isolate only the threes to be added. Any help or advice would be appreciated, thank you!

if (die1 == 3 || die2 == 3 || die3 == 3 || die4 == 3 || die5 == 3 ) {
    int addThree;
    addThree = die1 + die2 + die3 + die4 + die5;
        System.out.println();
        System.out.println(addThree);
}

Aucun commentaire:

Enregistrer un commentaire