I am new in Java and reading one of the java book and stuck on one program, the program is below

Code:

Forty students were asked to rate the quality of the food in the student cafeteria on a
scale of 1 to 10 (where 1 means awful and 10 means excellent). Place the 40 responses
in an integer array, and summarize the results of the poll.

Thanks for the reply but i am not talking abount loop statement, I am talking abount the below code after loop statement.

Quote:

++frequency[ responses[ answer ] ];

11-20-2011, 05:28 PM

Fubarable

Re: Unable to get the idea

His issue is with this statement:

Code:

++frequency[ responses[ answer ] ];

My suggestion is that you split this up into several lines to better understand it.

Code:

int thisAnswer = responses[answer];
++frequency[thisAnswer];

Note that

Code:

++frequency[thisAnswer];

is the same as

Code:

frequency[thisAnswer] = frequency[thisAnswer] + 1;

11-20-2011, 05:30 PM

Norm

Re: Unable to get the idea

Dyslexia, or need new glasses.

11-20-2011, 05:35 PM

gozuhair

Re: Unable to get the idea

Thanks for the reply, could you please explain it in more details, actually, I am always afraid from array topic and this time I dont want to compromise it.
If you can provide me an example then I will really appreciate you.

11-20-2011, 05:38 PM

Fubarable

Re: Unable to get the idea

Consider using a debugger such as one that is available from NetBeans or Eclipse (or likely whatever IDE you're using) and step through the code to see what happens to the frequency array at that line as this can tell you a lot.

11-20-2011, 05:40 PM

gozuhair

Re: Unable to get the idea

I am using Eclipse but i dont know how debugger works, will try to see the values in debugger and then let you the exact situation. Thank you very much