Sorry, scrap that last post. The arrayoutofbounds exception occurs because you are trying to write to index 10 but have initilzed an array of only 0-9 via -
int[] intervalValue = new int[intervals];
Main Topics
Browse All Topics I'm taking a beginner Java class, with the assignment to create a histogram program with the following output: (100 and 10 are user inputs).
How many numbers? 100
How many intervals? 10
Histogram
--------------------------
1 ****(4)
2 ******(6)
3 ***********(11)
4 *****************(17)
5 **************************
6 *************************(
7 *******(7)
8 ***(3)
9 (0)
10 *(1)
--------------------------
My code is giving the following output however, can anyone help me point out what is going wrong, thanks so much.
How Many Numbers? 10
How Many Intervals? 10
Histogram
--------------------------
1 **********(10)
2 **********(10)
3 **********(10)
4 **********(10)
5 **********(10)
6 **********(10)
7 **********(10)
8 **********(10)
9 **********(10)
10 **********(10)
For the input, 100 and 10 I get the error message:
Exception in thread "main" java.lang.ArrayIndexOutOfB
at Lab6.main(Lab6.java:44)
Which links to this code;
intervalValue[j]++;
I'm not sure how to attach the generator (.jar) file, it is supposed to just generate the random #'s for us. Thanks again.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
1. For user input: numbers = 10 and intervals = 10:
I suppose you want to increment the intervalValue[j] (line 44) only if the condition
generate[i] >= imin && generate[i] < imax
is true. If this is the case, then remove the semicolon at the end of the line 43
2. For user input: numbers = 100 and intervals = 10
You have an array of 10 integers
int[] intervalValue = new int[intervals];
and try to access an element outside of this limit:
// the variable j take values in the range 0-99
for (int j = 0; j<generate.length; j++){
intervalValue[j]++;
}
Ok, I've added the for loop ioanton suggested, and am now getting the following output, any ideas, and thanks everyone.
How Many Numbers? 5
How Many Intervals? 6
Histogram
--------------------------
1 *****************(17)
2 *****************(17)
3 *****************(17)
4 *****************(17)
5 *****************(17)
6 (0)
Business Accounts
Answer for Membership
by: a_bPosted on 2009-08-15 at 09:40:38ID: 25106010
Should be - intervalValue[j++].