How to stock in an Array the points of a Dice? java -


my aim stock how many times dice has faced number between 1 , 6 10 throws.

it should like:

1 = 3 time(s)

2 = 4 time(s)

3 = 0 time(s)

4 = 1 time(s)

5= 1 time(s)

6 = 1 time(s)

total = 10 times (or throws)

i've written far code

    int final faces = 6;     int final throws = 10;     int nbtimes[] = new int[faces];     int face;       ...       for(int thr = 1; thr < throws ; thr++){         face = throwdice();         if (face == face)         nbtimes[face] +=1;     } 

where throwdice() gives me random number between 1 , 6. have done.

the following line return true , redundant:

if (face == face) 

if you'll remove line (and predecessor) it'll work fine (as well):

...  ... int final faces = 6; int final throws = 10; int nbtimes[] = new int[faces]; int face;  ...  for(int thr = 0; thr < throws ; thr++){ // int thr = 0 !!! (if want 10 throws)     nbtimes[throwdice()] += 1; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -