How does k get the value of -5? You want k to have values from 0 to the size of the array -1
Type: Posts; User: Norm
How does k get the value of -5? You want k to have values from 0 to the size of the array -1
You need to explain what you are trying to do in this statement:
int [] freq = (int) (Math.random() * 10);
If freq must be an array, what is the purpose of the call to the random() method?
You did not say what you are trying to do. The following will compile:
int freq = (int) (Math.random() * 10);
But I don't know what you are trying to do. Please explain.
On the left of the = is a definition for an int array
on the right is a single int value.
The compiler won't like doing that assignment. It wants the same types on both sides of the =
What...
Is it working now?
If you get errors please copy and paste the full text here.
Do you understand what values the Random class's nextInt() method returns?
Add a println to print out the values returned by the method so you can see what it returns.
Why did you chose that...
Does it work as you want it to?
On line 16 the program tried to use an index that was not in the range of valid indexes for the array. Array indexes start at 0 and go to the array length-1. -3 is not a valid index.
Please post...
Go back and reread the assignment. It specifies where the count of the number of loops comes from.
It is NOT random!!
If you don't use arrays, that will make the program many times longer than it...
Do you know about arrays? This program should use an array NOT 10 separate variables.
What will be done inside of the first loop?
And then in the second loop?
You need to work out the logic of the program before you start writing the code. After you get the logic for the program worked out, you will see where to put the call to the random() method.
Can...
Explain what the code needs to do and why you think the Math class's random() method would be useful.
The for loop is a better fit when you know how many times you want to loop.
That would be one way.
That is what the assignment is all about. Go back and read post#1.
Count the number of numbers in each range.
Print out *s for each count.
To print many characters on one line use the
System.out.print("<THE CHAR(S) HERE>") method in a loop.
When you want to go to the next line use the println() method.
If you have a count of the...
Where are you having problems? List the steps the program need to do and work on them one at a time.
When you have a problem with a step, post the code and your questions.