java - What's wrong with this for loop? -


I am making a dice game for Android and I have this loop, which is an array rolled out on roll Fills with "j" It went like this

  int [] roll = new int [6]; {Roll [j] = (int) (monastery. Randem) * 5) for (int j: roll); Roll [ja] ++; Logs. I (getclass (). GetName (), "roll [[+ + + + + +] =" + roll [ja]); }   

except the output (in the logfile)

  roll [0] = 4 rolls [0] = 2 rolls [0] = 3 rolls [0] = 6 rolls [0] = 3 rolls [0] = 4   

and when I change the code on

  int [] roll = New int [6]; For (int j = 0; j and lt; roll length; j ++) {roll [j] = (int) (math.rendum) * 5); Roll [ja] ++; Logs. I (getclass (). GetName (), "roll [[+ + + + + +] =" + roll [ja]); }   

The output is correct

  rolls [0] = 4 rolls [1] = 2 rolls [2] = 3 rolls [3] = 6 rolls [4] = 3 rolls [5] = 4   

I should be a little stupid.

Statement:

 for  (int j: roll) < / Code>  

roll , not index since arrays are started in Java, value j zero for each of 6 iterations is.

Comments