Good day! I create an array of integer values, the values from 1000 to 9999, inclusive, should be entered into it via for when the program starts. Then I randomly click on a button and select one of the values. I put the size of the array 10,000. As a result, I often get the value 0, although if I output the entire array to the console, then there are no such values. Help me to understand! In the end, at the press of a button, I have to get only one 4-digit number ...
I create an array:
public int passArray[] = new int[10000]; I fill in:
for (int i = 1000; i < passArray.length; i++){ passArray[i] = i; } I deduce on clicking of the button:
int index; index = passArray[(int) (Math.random() * passArray.length)]; System.out.println(Integer.toString(index)); As a result, it gives the number, for example, 3443, then once again, it gives 5534, and once again I press and gives 0, I can give 0 again, in general, I can’t understand where they come from ... Tell me!