I'm just starting java programing and I've been doing really good so far. So the program I am having problems with works just after it goes through there is an error message, yet the program worked as I wanted it to. The program in question is supposed to role a die 1000 times and count how many times each side of the die was rolled out of 1000. its supposed to display this, which it does.
Here is my program: and the error message I put below it. Thanks for any help in advanced!
public class Test
{
public static void main(String[] args)
{//create array of 1,000 random numbers
int[] randomNumbers = new int[1000];
for(int i = 0; i < randomNumbers.length; i++)
randomNumbers[i] =1 +(int)(Math.random() * 6);
{ //initialize count
int[] counts = countInts(randomNumbers);
displayIntCount(counts);
}
}
public static int[] countInts(int[] ints)
{ //creat new array to hold occurence values
int[] counts = new int[6];
for(int i = 1; i <=counts.length; i++)
for(int j=0;j<ints.length;j++)
if(ints[j] == i)
counts[i-1]++;
return counts;
}
public static void displayIntCount(int[] counts)
{//display the occurrences
for (int i = 0; i < counts.length; i++)
System.out.println("The number 1 occurs "+counts[i]+" times \nThe number 2 occurs "+counts[i+1]+" times \nThe number 3 occurs "+counts[i + 2]+ " times \nThe number 4 occurs " +counts[i+3]+ " times \nThe number 5 occurs " +counts[i + 4]+ " times \nThe number 6 occurs "+counts[i + 5]+ " times");
}
}