Java: Random numbers
When you create an array in java you have to say how long it is in the beginning. You do that with the following line:
arrayNumber = new int[number];
This code is correct. The problem here is that there is no value currently stored inside of "number".
If you look at this line:
int number, randomNumber;
You create the variables but you never say what is stored inside of them. Normally Java would just put in a default value of 0. But because you are creating them in the main method (and because you should really always say what the value in a variable should be no matter where in your code), Java instead assumes that you forgot to give the variable a value and throws this error that you are getting (as far as I know).
So to fix your issue, you need to tell the program exactly what value is stored inside of the variable "number". In your case this should work just fine:
number = 10;
Just make sure you add this line into your code before the line where you create your array.

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now