+ 2
Why is my random number generator with a range not corresponding with my output?
it works when u put it alone in the output box but with some other info and a array. it's not working. I think it has to do something with the array or for loop. boxes[x] = ran.nextInt((21-10)-1 + 1) + 10; } } https://code.sololearn.com/c2JyX7EXoPtZ/?ref=app
1 Respuesta
+ 4
In your loop....
CHANGE:
n1 = boxes[x];
TO:
boxes[x] = n1;
The problem is that you're assigning the value from your array to n1, rather than assigning the value of n1 to your array. As such, since your arrays are empty, they default to 0 and that's why you receive 0 as the output for the weight. Swapping those variables around will resolve the issue.