This site requires JavaScript, please enable it in your browser!
Greenfoot back
Starlord_20
Starlord_20 wrote ...

2020/2/4

check for value

Starlord_20 Starlord_20

2020/2/4

#
 public void act() {
        int a = intInput("Anzahl Runden:")-1; int summe = 0;
        while( a > 0) {
            int random = (int) (6*Math.random()+1);
            getWorld().showText(""+random,x,3); x += 2;
            summe += random; a--;
        }
        getWorld().showText("Summe: "+summe,5,5);
    }
can I somehow check if the integer 'random' once had the value 1 during the while-loop? *btw int a has an integer input
danpost danpost

2020/2/4

#
Use a boolean flag. Initialize it before, test while inside (changing its value if random is 1) and check its value after the while loop to do whatever when 1 hits.
You need to login to post a reply.