Your for
loop count is exceeding over the array’s length
. Both the for loops should be run like
for (int count = 0; count < lottoNumbers.length; count++)
Also, you shouldn’t hardcode your length
values (5, 4) used in your count
comparisons for printing commas. Use the length
property as
for (int count = 0; count < lottoNumbers.length; count++)
{
if (count < lottoNumbers.length - 1) {
System.out.print(lottoNumbers[count]);
System.out.print(count == lottoNumbers.length - 2 ? "" : ", ");
} else {
System.out.println("\nPower Ball: "
+ lottoNumbers[count]);
}
}
0
solved ArrayIndexOutOfBounds error lottery program/ Uncompilable source code error