Re: Array counting problem

[HERE I GET AN ERROR, DONT KNOW WHAT TO PUT IN HERE!]

...what is the error?

...how should we know what to put in there? What should it do?

My suggestion is to put the code to the side for a minute, and outline how you would solve the problem if you walked into a room and was handed a pencil and paper. How would you keep track of how many of each number was rolled?

Once you have that outline finished translate it to code. This is how you figure out "what to put in there", you figure out "what it should do, exactly, in step by step order"

Re: Array counting problem

dice count wouldnt be an array it would seperate integers for each coun

Re: Array counting problem

Hello,

Your code already has what you want.

Please try to find out.

Just think of mathematics.

Syed.

Re: Array counting problem

A frequency counter is possibly one of the coolest ways to use an array, and no switch statement is required.

For a random number generator that generates numbers 0 - n

Create an array to count the frequency of occurrence of each random number of size 'n + 1'

For each random number generated, increment the corresponding array counter, freqArray[number]++

No switch or if required!

Then for the last part of the question, iterate the array (an enhanced for loop would be excellent for this) and print the result of each element of the array.

Re: Array counting problem

Guys,

Actually the values of array itself are what he needed.

For example, no. of 1's is available in dicecount[0], no. of 2's in dicecount[1] and so on.

Thats it.

You can just print somewhat like this:

System.out.println("count of 1's:"+dicecount[0]);

System.out.println("count of 2's:"+dicecount[1]);

...

Syed.

Re: Array counting problem

I still dont understand why you would initialize dice count as an array.

Re: Array counting problem

Re: Array counting problem