195k views
24 votes
What is wrong with each of the following code segments? int[] values; for (int i = 0; i < values.length; i++) { values[i] = i * i; }

User Domager
by
3.1k points

1 Answer

5 votes

Answer:

values have been declared but not initialized nor allocated memory. So you are not allowed to use "values.length"

User Gnath
by
3.4k points